Update haos-vm-v5.sh

more code optimization
This commit is contained in:
tteckster 2023-02-09 20:15:09 -05:00 committed by GitHub
parent 4d83642522
commit ae335b1155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@
# https://github.com/tteck/Proxmox/raw/main/LICENSE # https://github.com/tteck/Proxmox/raw/main/LICENSE
function header_info { function header_info {
clear
cat <<"EOF" cat <<"EOF"
__ __ ___ _ __ __ ____ _____ __ __ ___ _ __ __ ____ _____
/ / / /___ ____ ___ ___ / | __________(_)____/ /_____ _____v5/ /_ / __ \/ ___/ / / / /___ ____ ___ ___ / | __________(_)____/ /_____ _____v5/ /_ / __ \/ ___/
@ -15,7 +16,6 @@ cat <<"EOF"
EOF EOF
} }
clear
header_info header_info
echo -e "\n Loading..." echo -e "\n Loading..."
GEN_MAC=02:$(openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//' | tr '[:lower:]' '[:upper:]') GEN_MAC=02:$(openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//' | tr '[:lower:]' '[:upper:]')
@ -55,11 +55,9 @@ function error_exit() {
exit $EXIT exit $EXIT
} }
function cleanup_vmid() { function cleanup_vmid() {
if $(qm status $VMID &>/dev/null); then if qm status $VMID &>/dev/null; then
if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then qm stop $VMID &>/dev/null
qm stop $VMID qm destroy $VMID &>/dev/null
fi
qm destroy $VMID
fi fi
} }
function cleanup() { function cleanup() {
@ -71,7 +69,7 @@ pushd $TEMP_DIR >/dev/null
if whiptail --title "HOME ASSISTANT OS VM" --yesno "This will create a New Home Assistant OS VM. Proceed?" 10 58; then if whiptail --title "HOME ASSISTANT OS VM" --yesno "This will create a New Home Assistant OS VM. Proceed?" 10 58; then
: :
else else
clear && echo -e "⚠ User exited script \n" && exit header_info && echo -e "⚠ User exited script \n" && exit
fi fi
function msg_info() { function msg_info() {
@ -87,17 +85,16 @@ function msg_error() {
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}" echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
} }
function PVE_CHECK() { function PVE_CHECK() {
if [ `pveversion | grep "pve-manager/7.2\|7.3" | wc -l` -ne 1 ]; then if [ $(pveversion | grep -c "pve-manager/7\.[2-9]") -eq 0 ]; then
echo "⚠ This version of Proxmox Virtual Environment is not supported" echo -e "${CROSS} This version of Proxmox Virtual Environment is not supported"
echo "Requires PVE Version: =>7.2" echo -e "Requires PVE Version 7.2 or higher"
echo "Exiting..." echo -e "Exiting..."
sleep 2 sleep 2
exit exit
fi fi
} }
function ARCH_CHECK() { function ARCH_CHECK() {
ARCH=$(dpkg --print-architecture) if [ "$(dpkg --print-architecture)" != "amd64" ]; then
if [[ "$ARCH" != "amd64" ]]; then
echo -e "\n ${CROSS} This script will not work with PiMox! \n" echo -e "\n ${CROSS} This script will not work with PiMox! \n"
echo -e "Exiting..." echo -e "Exiting..."
sleep 2 sleep 2
@ -232,7 +229,6 @@ fi
if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create HAOS ${BRANCH} VM?" --no-button Do-Over 10 58); then if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create HAOS ${BRANCH} VM?" --no-button Do-Over 10 58); then
echo -e "${RD}Creating a HAOS VM using the above advanced settings${CL}" echo -e "${RD}Creating a HAOS VM using the above advanced settings${CL}"
else else
clear
header_info header_info
echo -e "${RD}Using Advanced Settings${CL}" echo -e "${RD}Using Advanced Settings${CL}"
advanced_settings advanced_settings
@ -240,12 +236,10 @@ fi
} }
function START_SCRIPT() { function START_SCRIPT() {
if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
clear
header_info header_info
echo -e "${BL}Using Default Settings${CL}" echo -e "${BL}Using Default Settings${CL}"
default_settings default_settings
else else
clear
header_info header_info
echo -e "${RD}Using Advanced Settings${CL}" echo -e "${RD}Using Advanced Settings${CL}"
advanced_settings advanced_settings