diff --git a/vm/haos-vm.sh b/vm/haos-vm.sh index f5b821e6..ad9827ea 100644 --- a/vm/haos-vm.sh +++ b/vm/haos-vm.sh @@ -1,5 +1,13 @@ #!/usr/bin/env bash +YW=`echo "\033[33m"` +BL=`echo "\033[36m"` +GN=`echo "\033[1;92m"` +CL=`echo "\033[m"` +BFR="\\r\\033[K" +HOLD="-" +CM="${GN}✓${CL}" + while true; do read -p "This will create a New Home Assistant OS VM. Proceed(y/n)?" yn case $yn in @@ -9,8 +17,7 @@ while true; do esac done clear -CL=`echo "\033[m"` -BL=`echo "\033[36m"` + function header_info { echo -e "${BL} _ _ ____ _____ @@ -23,6 +30,17 @@ echo -e "${BL} ${CL}" } header_info + +function msg_info() { + local msg="$1" + echo -ne " ${HOLD} ${YW}${msg}..." +} + +function msg_ok() { + local msg="$1" + echo -e "${BFR} ${CM} ${GN}${msg}${CL}" +} + set -o errexit set -o errtrace set -o nounset @@ -94,10 +112,10 @@ else "${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3) || exit done fi -info "Using ${BL}$STORAGE${CL} for Storage Location." +msg_ok "Using ${BL}$STORAGE${CL} for Storage Location." VMID=$(pvesh get /cluster/nextid) -info "Container ID is ${BL}$VMID${CL}." -echo -en "${GN} Getting URL for Latest Home Assistant Disk Image... " +msg_ok "Container ID is ${BL}$VMID${CL}." +msg_info "Getting URL for Latest Home Assistant Disk Image" RELEASE_TYPE=qcow2 URL=$(cat</dev/null set +o errtrace ( -echo -e "${CM} ${CL} \r" - echo -en "${GN} Adding Serial Port and Configuring Console... " +msg_info "Created HAOS VM" + + msg_info "Adding Serial Port and Configuring Console" trap ' warn "Unable to configure serial port. VM is still functional." if [ "$(qm config $VMID | sed -n ''/serial0/p'')" != "" ]; then @@ -167,12 +188,12 @@ echo -e "${CM} ${CL} \r" fi exit ' ERR - echo -e "${CM} ${CL} \r" + msg_ok "Added Serial Port and Configured Console" if [ "$(command -v kpartx)" = "" ]; then - echo -en "${GN} Installing kpartx... " + msg_info "Installing kpartx" apt-get update >/dev/null apt-get -qqy install kpartx &>/dev/null - echo -e "${CM} ${CL} \r" + msg_ok "Installed kpartx" fi DISK1_PATH="$(pvesm path $DISK1_REF)" DISK1_PART1="$(kpartx -al $DISK1_PATH | awk 'NR==1 {print $1}')" @@ -188,8 +209,8 @@ echo -e "${CM} ${CL} \r" sed -i 's/$/ console=ttyS0/' ${TEMP_MOUNT}/cmdline.txt qm set $VMID -serial0 socket >/dev/null ) -#echo -en "${GN} Starting Home Assistant OS VM... " -#qm start $VMID -#echo -e "${CM} ${CL} \n" +msg_info "Starting Home Assistant OS (${VM_NAME}) VM" +qm start $VMID +msg_ok "Started Home Assistant OS (${VM_NAME}) VM" echo -e "${GN} Completed Successfully!${CL} (${VM_NAME}) VM ID is ${BL}${VMID}${CL} \n"