From bfb873f5ea4e76e6f77b03300aa123e4c18f0637 Mon Sep 17 00:00:00 2001 From: tteckster Date: Wed, 27 Apr 2022 07:26:15 -0400 Subject: [PATCH 01/10] Update haos_vm.sh --- vm/haos_vm.sh | 109 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 98 insertions(+), 11 deletions(-) diff --git a/vm/haos_vm.sh b/vm/haos_vm.sh index 5b2a9a4f..bafbfe13 100644 --- a/vm/haos_vm.sh +++ b/vm/haos_vm.sh @@ -54,10 +54,18 @@ function default_settings() { VMID=$NEXTID echo -e "${DGN}Using VM Name ${BGN}haos${STABLE}${CL}" VM_NAME=haos${STABLE} - echo -e "${DGN}Using ${BGN}2vCPU${CL}" - CORE_COUNT="2" - echo -e "${DGN}Using ${BGN}4096MiB${CL}" - RAM_SIZE="4096" + echo -e "${DGN}Using ${BGN}2${CL}${DGN}vCPU${CL}" + CORE_COUNT="2" + echo -e "${DGN}Using ${BGN}4096${CL}${DGN}MiB RAM${CL}" + RAM_SIZE="4096" + echo -e "${DGN}Using Bridge ${BGN}vmbr0${CL}" + BRG="vmbr0" + echo -e "${DGN}Using Static IP Address ${BGN}DHCP${CL}" + NET=dhcp + echo -e "${DGN}Using Gateway Address ${BGN}NONE${CL}" + GATE="" + echo -e "${DGN}Using VLAN Tag ${BGN}NONE${CL}" + VLAN="" echo -e "${DGN}Start VM when completed ${BGN}yes${CL}" START_VM="yes" @@ -119,7 +127,7 @@ header_info echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" echo -e "${YW}Allocate RAM in MiB, or Press [ENTER] for Default: 4096 " read RAM_SIZE if [ -z $RAM_SIZE ]; then RAM_SIZE="4096"; fi; @@ -132,8 +140,82 @@ header_info echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}" - echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" + echo -e "${YW}Enter a Bridge, or Press [ENTER] for Default: vmbr0 " + read BRG + if [ -z $BRG ]; then BRG="vmbr0"; fi; + echo -en "${DGN}Set Bridge To ${BL}$BRG${CL}" +echo -e " ${CM}${CL} \n" +sleep 1 +clear +header_info + echo -e "${RD}Using Advanced Settings${CL}" + echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" + echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" + echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" + echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" + echo -e "${YW}Enter a Static IP Address, or Press [ENTER] for Default: DHCP " + read NET + if [ -z $NET ]; then NET="dhcp"; fi; + echo -en "${DGN}Set Static IP Address To ${BL}$NET${CL}" +echo -e " ${CM}${CL} \n" +sleep 1 +clear +header_info + echo -e "${RD}Using Advanced Settings${CL}" + echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" + echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" + echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" + echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" + echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}" + echo -e "${YW}Enter a Gateway IP, or Press [ENTER] for Default: NONE " + read GATE1 + if [ -z $GATE1 ]; then GATE1="NONE" GATE=""; + echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}" + else + GATE=",gw=$GATE1" + echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}" + fi; +echo -e " ${CM}${CL} \n" +sleep 1 +clear +header_info + echo -e "${RD}Using Advanced Settings${CL}" + echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" + echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" + echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" + echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" + echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}" + echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}" + echo -e "${YW}Enter a VLAN Tag, or Press [ENTER] for Default: NONE " + read VLAN1 + if [ -z $VLAN1 ]; then VLAN1="NONE" VLAN=""; + echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}" + else + VLAN=",tag=$VLAN1" + echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}" + fi; +echo -e " ${CM}${CL} \n" +sleep 1 +clear +header_info + echo -e "${RD}Using Advanced Settings${CL}" + echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" + echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" + echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB${CL}" + echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" + echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}" + echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}" + echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}" echo -e "${YW}Start VM when completed, or Press [ENTER] for Default: yes " read START_VM if [ -z $START_VM ]; then START_VM="yes"; @@ -148,9 +230,13 @@ header_info echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}" - echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}" - echo -e "${DGN}Start VM when completed ${BGN}$START_VM${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB${CL}" + echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" + echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}" + echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}" + echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}" + echo -e "${DGN}Start VM when completed ${BGN}$START_VM${CL}" read -p "Are these settings correct(y/n)? " -n 1 -r echo @@ -267,7 +353,8 @@ done msg_ok "Extracted Disk Image" msg_info "Creating HAOS VM" -qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=vmbr0 \ +qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME \ + -net0 virtio,bridge=$BRG ip=$NET$GATE$VLAN \ -onboot 1 -ostype l26 -scsihw virtio-scsi-pci pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null qm importdisk $VMID ${FILE%.*} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null From 9e4459c13b989e009be2d4769f16eba0596f4cc8 Mon Sep 17 00:00:00 2001 From: tteckster Date: Wed, 27 Apr 2022 07:32:01 -0400 Subject: [PATCH 02/10] Update haos_vm.sh --- vm/haos_vm.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vm/haos_vm.sh b/vm/haos_vm.sh index bafbfe13..ed541add 100644 --- a/vm/haos_vm.sh +++ b/vm/haos_vm.sh @@ -353,8 +353,7 @@ done msg_ok "Extracted Disk Image" msg_info "Creating HAOS VM" -qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME \ - -net0 virtio,bridge=$BRG ip=$NET$GATE$VLAN \ +qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG,ip=$NET$GATE$VLAN \ -onboot 1 -ostype l26 -scsihw virtio-scsi-pci pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null qm importdisk $VMID ${FILE%.*} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null From 9941a47a8c8f9fb4dc46c7dc01ecc185daa10ab3 Mon Sep 17 00:00:00 2001 From: tteckster Date: Wed, 27 Apr 2022 07:36:30 -0400 Subject: [PATCH 03/10] Update haos_vm.sh --- vm/haos_vm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/haos_vm.sh b/vm/haos_vm.sh index ed541add..9a992221 100644 --- a/vm/haos_vm.sh +++ b/vm/haos_vm.sh @@ -353,7 +353,7 @@ done msg_ok "Extracted Disk Image" msg_info "Creating HAOS VM" -qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG,ip=$NET$GATE$VLAN \ +qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG -ipconfig ip=$NET$GATE$VLAN \ -onboot 1 -ostype l26 -scsihw virtio-scsi-pci pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null qm importdisk $VMID ${FILE%.*} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null From 274a355414f6753599330571d29557ef2e4bed17 Mon Sep 17 00:00:00 2001 From: tteckster Date: Wed, 27 Apr 2022 07:42:28 -0400 Subject: [PATCH 04/10] Update haos_vm.sh --- vm/haos_vm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/haos_vm.sh b/vm/haos_vm.sh index 9a992221..9e89b953 100644 --- a/vm/haos_vm.sh +++ b/vm/haos_vm.sh @@ -353,7 +353,7 @@ done msg_ok "Extracted Disk Image" msg_info "Creating HAOS VM" -qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG -ipconfig ip=$NET$GATE$VLAN \ +qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG$VLAN -ipconfig0 ip=$NET$GATE \ -onboot 1 -ostype l26 -scsihw virtio-scsi-pci pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null qm importdisk $VMID ${FILE%.*} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null From 64d9231634c36cf2382fdd60ddad4081e0789685 Mon Sep 17 00:00:00 2001 From: tteckster Date: Wed, 27 Apr 2022 08:12:50 -0400 Subject: [PATCH 05/10] Update haos_vm.sh --- vm/haos_vm.sh | 52 ++++++--------------------------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/vm/haos_vm.sh b/vm/haos_vm.sh index 9e89b953..975e9918 100644 --- a/vm/haos_vm.sh +++ b/vm/haos_vm.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]') NEXTID=$(pvesh get /cluster/nextid) RELEASE=$(curl -sX GET "https://api.github.com/repos/home-assistant/operating-system/releases" | awk '/tag_name/{print $4;exit}' FS='[""]') STABLE="7.6" @@ -60,10 +61,7 @@ function default_settings() { RAM_SIZE="4096" echo -e "${DGN}Using Bridge ${BGN}vmbr0${CL}" BRG="vmbr0" - echo -e "${DGN}Using Static IP Address ${BGN}DHCP${CL}" - NET=dhcp - echo -e "${DGN}Using Gateway Address ${BGN}NONE${CL}" - GATE="" + echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" echo -e "${DGN}Using VLAN Tag ${BGN}NONE${CL}" VLAN="" echo -e "${DGN}Start VM when completed ${BGN}yes${CL}" @@ -149,41 +147,6 @@ header_info echo -e " ${CM}${CL} \n" sleep 1 clear -header_info - echo -e "${RD}Using Advanced Settings${CL}" - echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" - echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" - echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" - echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" - echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" - echo -e "${YW}Enter a Static IP Address, or Press [ENTER] for Default: DHCP " - read NET - if [ -z $NET ]; then NET="dhcp"; fi; - echo -en "${DGN}Set Static IP Address To ${BL}$NET${CL}" -echo -e " ${CM}${CL} \n" -sleep 1 -clear -header_info - echo -e "${RD}Using Advanced Settings${CL}" - echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" - echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" - echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" - echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" - echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" - echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}" - echo -e "${YW}Enter a Gateway IP, or Press [ENTER] for Default: NONE " - read GATE1 - if [ -z $GATE1 ]; then GATE1="NONE" GATE=""; - echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}" - else - GATE=",gw=$GATE1" - echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}" - fi; -echo -e " ${CM}${CL} \n" -sleep 1 -clear header_info echo -e "${RD}Using Advanced Settings${CL}" echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" @@ -192,8 +155,7 @@ header_info echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" - echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}" - echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}" + echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" echo -e "${YW}Enter a VLAN Tag, or Press [ENTER] for Default: NONE " read VLAN1 if [ -z $VLAN1 ]; then VLAN1="NONE" VLAN=""; @@ -213,8 +175,7 @@ header_info echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB${CL}" echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" - echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}" - echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}" + echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}" echo -e "${YW}Start VM when completed, or Press [ENTER] for Default: yes " read START_VM @@ -233,8 +194,7 @@ header_info echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB${CL}" echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" - echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}" - echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}" + echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}" echo -e "${DGN}Start VM when completed ${BGN}$START_VM${CL}" @@ -353,7 +313,7 @@ done msg_ok "Extracted Disk Image" msg_info "Creating HAOS VM" -qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG$VLAN -ipconfig0 ip=$NET$GATE \ +qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN \ -onboot 1 -ostype l26 -scsihw virtio-scsi-pci pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null qm importdisk $VMID ${FILE%.*} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null From 3681f86e66025920a1d9d5a5b29aef1656fe11de Mon Sep 17 00:00:00 2001 From: tteckster Date: Wed, 27 Apr 2022 08:32:01 -0400 Subject: [PATCH 06/10] Update haos_vm.sh --- vm/haos_vm.sh | 80 ++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/vm/haos_vm.sh b/vm/haos_vm.sh index 975e9918..2ed161f2 100644 --- a/vm/haos_vm.sh +++ b/vm/haos_vm.sh @@ -13,6 +13,41 @@ CL=`echo "\033[m"` BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail +shopt -s expand_aliases +alias die='EXIT=$? LINE=$LINENO error_exit' +trap die ERR +trap cleanup EXIT + +function error_exit() { + trap - ERR + local reason="Unknown failure occured." + local msg="${1:-$reason}" + local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" + echo -e "$flag $msg" 1>&2 + [ ! -z ${VMID-} ] && cleanup_vmid + exit $EXIT +} + +function cleanup_vmid() { + if $(qm status $VMID &>/dev/null); then + if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then + qm stop $VMID + fi + qm destroy $VMID + fi +} + +function cleanup() { + popd >/dev/null + rm -rf $TEMP_DIR +} + +TEMP_DIR=$(mktemp -d) +pushd $TEMP_DIR >/dev/null while true; do read -p "This will create a New Home Assistant OS VM. Proceed(y/n)?" yn @@ -217,51 +252,6 @@ function start_script() { start_script -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -trap cleanup EXIT -function error_exit() { - trap - ERR - local DEFAULT='Unknown failure occured.' - local REASON="\e[97m${1:-$DEFAULT}\e[39m" - local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE" - msg "$FLAG $REASON" - [ ! -z ${VMID-} ] && cleanup_vmid - exit $EXIT -} -function warn() { - local REASON="\e[97m$1\e[39m" - local FLAG="\e[93m[WARNING]\e[39m" - msg "$FLAG $REASON" -} -function info() { - local REASON="$1" - local FLAG="\e[36m[INFO]\e[39m" - msg "$FLAG $REASON" -} -function msg() { - local TEXT="$1" - echo -e "$TEXT" -} -function cleanup_vmid() { - if $(qm status $VMID &>/dev/null); then - if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then - qm stop $VMID - fi - qm destroy $VMID - fi -} -function cleanup() { - popd >/dev/null - rm -rf $TEMP_DIR -} -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null while read -r line; do TAG=$(echo $line | awk '{print $1}') TYPE=$(echo $line | awk '{printf "%-10s", $2}') From 8db8608e7fd87b83ea5e191df1d12de8be1d4033 Mon Sep 17 00:00:00 2001 From: tteckster Date: Wed, 27 Apr 2022 08:35:14 -0400 Subject: [PATCH 07/10] Update haos-vm-v3.sh --- vm/haos-vm-v3.sh | 68 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/vm/haos-vm-v3.sh b/vm/haos-vm-v3.sh index 360cee9e..66b3f40b 100644 --- a/vm/haos-vm-v3.sh +++ b/vm/haos-vm-v3.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]') NEXTID=$(pvesh get /cluster/nextid) RELEASE=$(curl -sX GET "https://api.github.com/repos/home-assistant/operating-system/releases" | awk '/tag_name/{print $4;exit}' FS='[""]') STABLE="7.6" @@ -89,10 +90,15 @@ function default_settings() { VMID=$NEXTID echo -e "${DGN}Using VM Name ${BGN}haos${STABLE}${CL}" VM_NAME=haos${STABLE} - echo -e "${DGN}Using ${BGN}2vCPU${CL}" - CORE_COUNT="2" - echo -e "${DGN}Using ${BGN}4096MiB${CL}" - RAM_SIZE="4096" + echo -e "${DGN}Using ${BGN}2${CL}${DGN}vCPU${CL}" + CORE_COUNT="2" + echo -e "${DGN}Using ${BGN}4096${CL}${DGN}MiB RAM${CL}" + RAM_SIZE="4096" + echo -e "${DGN}Using Bridge ${BGN}vmbr0${CL}" + BRG="vmbr0" + echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" + echo -e "${DGN}Using VLAN Tag ${BGN}NONE${CL}" + VLAN="" echo -e "${DGN}Start VM when completed ${BGN}yes${CL}" START_VM="yes" @@ -154,7 +160,7 @@ header_info echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" echo -e "${YW}Allocate RAM in MiB, or Press [ENTER] for Default: 4096 " read RAM_SIZE if [ -z $RAM_SIZE ]; then RAM_SIZE="4096"; fi; @@ -167,8 +173,45 @@ header_info echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}" - echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" + echo -e "${YW}Enter a Bridge, or Press [ENTER] for Default: vmbr0 " + read BRG + if [ -z $BRG ]; then BRG="vmbr0"; fi; + echo -en "${DGN}Set Bridge To ${BL}$BRG${CL}" +echo -e " ${CM}${CL} \n" +sleep 1 +clear +header_info + echo -e "${RD}Using Advanced Settings${CL}" + echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" + echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" + echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" + echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" + echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" + echo -e "${YW}Enter a VLAN Tag, or Press [ENTER] for Default: NONE " + read VLAN1 + if [ -z $VLAN1 ]; then VLAN1="NONE" VLAN=""; + echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}" + else + VLAN=",tag=$VLAN1" + echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}" + fi; +echo -e " ${CM}${CL} \n" +sleep 1 +clear +header_info + echo -e "${RD}Using Advanced Settings${CL}" + echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" + echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" + echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB${CL}" + echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" + echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" + echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}" echo -e "${YW}Start VM when completed, or Press [ENTER] for Default: yes " read START_VM if [ -z $START_VM ]; then START_VM="yes"; @@ -183,9 +226,12 @@ header_info echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}" - echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}" - echo -e "${DGN}Start VM when completed ${BGN}$START_VM${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB${CL}" + echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" + echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" + echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}" + echo -e "${DGN}Start VM when completed ${BGN}$START_VM${CL}" read -p "Are these settings correct(y/n)? " -n 1 -r echo @@ -257,7 +303,7 @@ done msg_ok "Extracted Disk Image" msg_info "Creating HAOS VM" -qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=vmbr0 \ +qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN \ -onboot 1 -ostype l26 -scsihw virtio-scsi-pci pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null qm importdisk $VMID ${FILE%.*} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null From 6725b6cb5632fb15044347d864e7b3cc6471d869 Mon Sep 17 00:00:00 2001 From: tteckster Date: Wed, 27 Apr 2022 08:36:09 -0400 Subject: [PATCH 08/10] Update haos_vm.sh --- vm/haos_vm.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/haos_vm.sh b/vm/haos_vm.sh index 2ed161f2..66b3f40b 100644 --- a/vm/haos_vm.sh +++ b/vm/haos_vm.sh @@ -264,7 +264,7 @@ while read -r line; do STORAGE_MENU+=( "$TAG" "$ITEM" "OFF" ) done < <(pvesm status -content images | awk 'NR>1') if [ $((${#STORAGE_MENU[@]}/3)) -eq 0 ]; then - warn "'Disk image' needs to be selected for at least one storage location." + echo -e "'Disk image' needs to be selected for at least one storage location." die "Unable to detect valid storage location." elif [ $((${#STORAGE_MENU[@]}/3)) -eq 1 ]; then STORAGE=${STORAGE_MENU[0]} @@ -318,7 +318,7 @@ msg_ok "Created HAOS VM ${CL}${BL}${VM_NAME}" msg_info "Adding Serial Port and Configuring Console" trap ' - warn "Unable to configure serial port. VM is still functional." + echo -e "Unable to configure serial port. VM is still functional." if [ "$(qm config $VMID | sed -n ''/serial0/p'')" != "" ]; then qm set $VMID --delete serial0 >/dev/null fi From 75fd46e27d7f9c6983fddb81af3b7091f990448e Mon Sep 17 00:00:00 2001 From: tteckster Date: Wed, 27 Apr 2022 08:59:10 -0400 Subject: [PATCH 09/10] Update haos-vm-v3.sh --- vm/haos-vm-v3.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/vm/haos-vm-v3.sh b/vm/haos-vm-v3.sh index 66b3f40b..2ea4c203 100644 --- a/vm/haos-vm-v3.sh +++ b/vm/haos-vm-v3.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]') +GEN_MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]') NEXTID=$(pvesh get /cluster/nextid) RELEASE=$(curl -sX GET "https://api.github.com/repos/home-assistant/operating-system/releases" | awk '/tag_name/{print $4;exit}' FS='[""]') STABLE="7.6" @@ -96,7 +96,8 @@ function default_settings() { RAM_SIZE="4096" echo -e "${DGN}Using Bridge ${BGN}vmbr0${CL}" BRG="vmbr0" - echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" + echo -e "${DGN}Using MAC Address ${BGN}$GEN_MAC${CL}" + MAC=$GEN_MAC echo -e "${DGN}Using VLAN Tag ${BGN}NONE${CL}" VLAN="" echo -e "${DGN}Start VM when completed ${BGN}yes${CL}" @@ -182,6 +183,21 @@ header_info echo -e " ${CM}${CL} \n" sleep 1 clear +header_info + echo -e "${RD}Using Advanced Settings${CL}" + echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" + echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" + echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" + echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" + echo -e "${YW}Enter a Valid MAC Address, or Press [ENTER] for Generated MAC: $GEN_MAC " + read MAC + if [ -z $MAC ]; then MAC=$GEN_MAC; fi; + echo -en "${DGN}Set MAC Address To ${BL}$MAC${CL}" +echo -e " ${CM}${CL} \n" +sleep 1 +clear header_info echo -e "${RD}Using Advanced Settings${CL}" echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" From ee426dbe8dc12c977be21219edb1ab009729a8b7 Mon Sep 17 00:00:00 2001 From: tteckster Date: Wed, 27 Apr 2022 09:05:49 -0400 Subject: [PATCH 10/10] Update haos_vm.sh --- vm/haos_vm.sh | 152 +++++++++++++++++++------------------------------- 1 file changed, 58 insertions(+), 94 deletions(-) diff --git a/vm/haos_vm.sh b/vm/haos_vm.sh index 66b3f40b..5b2a9a4f 100644 --- a/vm/haos_vm.sh +++ b/vm/haos_vm.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]') NEXTID=$(pvesh get /cluster/nextid) RELEASE=$(curl -sX GET "https://api.github.com/repos/home-assistant/operating-system/releases" | awk '/tag_name/{print $4;exit}' FS='[""]') STABLE="7.6" @@ -13,41 +12,6 @@ CL=`echo "\033[m"` BFR="\\r\\033[K" HOLD="-" CM="${GN}✓${CL}" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR -trap cleanup EXIT - -function error_exit() { - trap - ERR - local reason="Unknown failure occured." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - [ ! -z ${VMID-} ] && cleanup_vmid - exit $EXIT -} - -function cleanup_vmid() { - if $(qm status $VMID &>/dev/null); then - if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then - qm stop $VMID - fi - qm destroy $VMID - fi -} - -function cleanup() { - popd >/dev/null - rm -rf $TEMP_DIR -} - -TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null while true; do read -p "This will create a New Home Assistant OS VM. Proceed(y/n)?" yn @@ -90,15 +54,10 @@ function default_settings() { VMID=$NEXTID echo -e "${DGN}Using VM Name ${BGN}haos${STABLE}${CL}" VM_NAME=haos${STABLE} - echo -e "${DGN}Using ${BGN}2${CL}${DGN}vCPU${CL}" - CORE_COUNT="2" - echo -e "${DGN}Using ${BGN}4096${CL}${DGN}MiB RAM${CL}" - RAM_SIZE="4096" - echo -e "${DGN}Using Bridge ${BGN}vmbr0${CL}" - BRG="vmbr0" - echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" - echo -e "${DGN}Using VLAN Tag ${BGN}NONE${CL}" - VLAN="" + echo -e "${DGN}Using ${BGN}2vCPU${CL}" + CORE_COUNT="2" + echo -e "${DGN}Using ${BGN}4096MiB${CL}" + RAM_SIZE="4096" echo -e "${DGN}Start VM when completed ${BGN}yes${CL}" START_VM="yes" @@ -160,7 +119,7 @@ header_info echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}" echo -e "${YW}Allocate RAM in MiB, or Press [ENTER] for Default: 4096 " read RAM_SIZE if [ -z $RAM_SIZE ]; then RAM_SIZE="4096"; fi; @@ -173,45 +132,8 @@ header_info echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" - echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" - echo -e "${YW}Enter a Bridge, or Press [ENTER] for Default: vmbr0 " - read BRG - if [ -z $BRG ]; then BRG="vmbr0"; fi; - echo -en "${DGN}Set Bridge To ${BL}$BRG${CL}" -echo -e " ${CM}${CL} \n" -sleep 1 -clear -header_info - echo -e "${RD}Using Advanced Settings${CL}" - echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" - echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" - echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" - echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB RAM${CL}" - echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" - echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" - echo -e "${YW}Enter a VLAN Tag, or Press [ENTER] for Default: NONE " - read VLAN1 - if [ -z $VLAN1 ]; then VLAN1="NONE" VLAN=""; - echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}" - else - VLAN=",tag=$VLAN1" - echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}" - fi; -echo -e " ${CM}${CL} \n" -sleep 1 -clear -header_info - echo -e "${RD}Using Advanced Settings${CL}" - echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" - echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" - echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" - echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB${CL}" - echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" - echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" - echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}" echo -e "${YW}Start VM when completed, or Press [ENTER] for Default: yes " read START_VM if [ -z $START_VM ]; then START_VM="yes"; @@ -226,12 +148,9 @@ header_info echo -e "${DGN}Using Version ${BGN}$BRANCH${CL}" echo -e "${DGN}Using VM ID ${BGN}$VMID${CL}" echo -e "${DGN}Using VM Name ${BGN}$VM_NAME${CL}" - echo -e "${DGN}Using ${BGN}${CORE_COUNT}${CL}${DGN}vCPU${CL}" - echo -e "${DGN}Using ${BGN}${RAM_SIZE}${CL}${DGN}MiB${CL}" - echo -e "${DGN}Using Bridge ${BGN}${BRG}${CL}" - echo -e "${DGN}Using MAC Address ${BGN}$MAC${CL}" - echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}" - echo -e "${DGN}Start VM when completed ${BGN}$START_VM${CL}" + echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}" + echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}" + echo -e "${DGN}Start VM when completed ${BGN}$START_VM${CL}" read -p "Are these settings correct(y/n)? " -n 1 -r echo @@ -252,6 +171,51 @@ function start_script() { start_script +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail +shopt -s expand_aliases +alias die='EXIT=$? LINE=$LINENO error_exit' +trap die ERR +trap cleanup EXIT +function error_exit() { + trap - ERR + local DEFAULT='Unknown failure occured.' + local REASON="\e[97m${1:-$DEFAULT}\e[39m" + local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE" + msg "$FLAG $REASON" + [ ! -z ${VMID-} ] && cleanup_vmid + exit $EXIT +} +function warn() { + local REASON="\e[97m$1\e[39m" + local FLAG="\e[93m[WARNING]\e[39m" + msg "$FLAG $REASON" +} +function info() { + local REASON="$1" + local FLAG="\e[36m[INFO]\e[39m" + msg "$FLAG $REASON" +} +function msg() { + local TEXT="$1" + echo -e "$TEXT" +} +function cleanup_vmid() { + if $(qm status $VMID &>/dev/null); then + if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then + qm stop $VMID + fi + qm destroy $VMID + fi +} +function cleanup() { + popd >/dev/null + rm -rf $TEMP_DIR +} +TEMP_DIR=$(mktemp -d) +pushd $TEMP_DIR >/dev/null while read -r line; do TAG=$(echo $line | awk '{print $1}') TYPE=$(echo $line | awk '{printf "%-10s", $2}') @@ -264,7 +228,7 @@ while read -r line; do STORAGE_MENU+=( "$TAG" "$ITEM" "OFF" ) done < <(pvesm status -content images | awk 'NR>1') if [ $((${#STORAGE_MENU[@]}/3)) -eq 0 ]; then - echo -e "'Disk image' needs to be selected for at least one storage location." + warn "'Disk image' needs to be selected for at least one storage location." die "Unable to detect valid storage location." elif [ $((${#STORAGE_MENU[@]}/3)) -eq 1 ]; then STORAGE=${STORAGE_MENU[0]} @@ -303,7 +267,7 @@ done msg_ok "Extracted Disk Image" msg_info "Creating HAOS VM" -qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN \ +qm create $VMID -agent 1 -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $VM_NAME -net0 virtio,bridge=vmbr0 \ -onboot 1 -ostype l26 -scsihw virtio-scsi-pci pvesm alloc $STORAGE $VMID $DISK0 128 1>&/dev/null qm importdisk $VMID ${FILE%.*} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null @@ -318,7 +282,7 @@ msg_ok "Created HAOS VM ${CL}${BL}${VM_NAME}" msg_info "Adding Serial Port and Configuring Console" trap ' - echo -e "Unable to configure serial port. VM is still functional." + warn "Unable to configure serial port. VM is still functional." if [ "$(qm config $VMID | sed -n ''/serial0/p'')" != "" ]; then qm set $VMID --delete serial0 >/dev/null fi