2026-05-21 19:04:47 +02:00
#!/usr/bin/env bash
2023-02-07 12:15:22 -05:00
2026-01-06 13:28:12 +01:00
# Copyright (c) 2021-2026 tteck
2023-02-07 12:15:22 -05:00
# Author: tteck (tteckster)
# License: MIT
2024-11-02 08:48:05 +01:00
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
2023-02-07 12:15:22 -05:00
2025-04-01 10:25:46 +02:00
source /dev/stdin <<< $( curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func)
2025-02-10 09:13:09 +01:00
2023-01-25 10:42:35 -05:00
function header_info {
2023-03-22 20:48:20 -04:00
cat <<"EOF"
2023-01-25 10:42:35 -05:00
____ _ __ ___
/ __ \( _) | / /___ _ __
/ /_/ / / /| _/ / __ \| | /_/
/ ____/ / / / / /_/ /> <
__ __ /_/_ /_/_/ /_/\_ ___/_/| _| __ ____ _____
2023-03-22 20:48:20 -04:00
/ / / /___ ____ ___ ___ / | __________( _) ____/ /_____ _____ / /_ / __ \/ ___/
2023-01-25 10:42:35 -05:00
/ /_/ / __ \/ __ ` __ \/ _ \ / /| | / ___/ ___/ / ___/ __/ __ ` / __ \/ __/ / / / /\_ _ \
/ __ / /_/ / / / / / / __/ / ___ | ( __ | __ ) ( __ ) /_/ /_/ / / / / /_ / /_/ /___/ /
/_/ /_/\_ ___/_/ /_/ /_/\_ __/ /_/ | _/____/____/_/____/\_ _/\_ _,_/_/ /_/\_ _/ \_ ___//____/
EOF
}
clear
header_info
2025-06-18 22:08:23 +02:00
echo -e "\n Loading..."
GEN_MAC = 02:$( openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//' )
2025-02-10 09:13:09 +01:00
RANDOM_UUID = " $( cat /proc/sys/kernel/random/uuid) "
2025-06-18 22:08:23 +02:00
VERSIONS =( stable beta dev)
2025-02-10 09:13:09 +01:00
METHOD = ""
NSAPP = "pimox-haos-vm"
var_os = "pimox-haos"
DISK_SIZE = "32G"
2025-06-18 22:08:23 +02:00
for version in " ${ VERSIONS [@] } " ; do
eval " $version = $( curl -fsSL https://raw.githubusercontent.com/home-assistant/version/master/stable.json | grep '"ova"' | cut -d '"' -f 4) "
done
2023-03-22 20:48:20 -04:00
YW = $( echo "\033[33m" )
BL = $( echo "\033[36m" )
RD = $( echo "\033[01;31m" )
BGN = $( echo "\033[4;92m" )
GN = $( echo "\033[1;92m" )
DGN = $( echo "\033[32m" )
CL = $( echo "\033[m" )
2025-06-18 22:08:23 +02:00
CL = $( echo "\033[m" )
BOLD = $( echo "\033[1m" )
2022-08-06 15:23:25 -04:00
BFR = "\\r\\033[K"
2025-06-18 22:08:23 +02:00
HOLD = " "
TAB = " "
CM = " ${ TAB } ✔️ ${ TAB }${ CL } "
CROSS = " ${ TAB } ✖️ ${ TAB }${ CL } "
INFO = " ${ TAB } 💡 ${ TAB }${ CL } "
OS = " ${ TAB } 🖥️ ${ TAB }${ CL } "
CONTAINERTYPE = " ${ TAB } 📦 ${ TAB }${ CL } "
DISKSIZE = " ${ TAB } 💾 ${ TAB }${ CL } "
CPUCORE = " ${ TAB } 🧠 ${ TAB }${ CL } "
RAMSIZE = " ${ TAB } 🛠️ ${ TAB }${ CL } "
CONTAINERID = " ${ TAB } 🆔 ${ TAB }${ CL } "
HOSTNAME = " ${ TAB } 🏠 ${ TAB }${ CL } "
BRIDGE = " ${ TAB } 🌉 ${ TAB }${ CL } "
GATEWAY = " ${ TAB } 🌐 ${ TAB }${ CL } "
DEFAULT = " ${ TAB } ⚙️ ${ TAB }${ CL } "
MACADDRESS = " ${ TAB } 🔗 ${ TAB }${ CL } "
VLANTAG = " ${ TAB } 🏷️ ${ TAB }${ CL } "
CREATING = " ${ TAB } 🚀 ${ TAB }${ CL } "
ADVANCED = " ${ TAB } 🧩 ${ TAB }${ CL } "
CLOUD = " ${ TAB } ☁️ ${ TAB }${ CL } "
THIN = "discard=on,ssd=1,"
set -e
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
2022-08-06 15:23:25 -04:00
trap cleanup EXIT
2026-02-23 14:30:48 +01:00
trap 'post_update_to_api "failed" "130"' SIGINT
trap 'post_update_to_api "failed" "143"' SIGTERM
trap 'post_update_to_api "failed" "129"; exit 129' SIGHUP
2025-06-18 22:08:23 +02:00
function error_handler() {
local exit_code = " $? "
local line_number = " $1 "
local command = " $2 "
local error_message = " ${ RD } [ERROR] ${ CL } in line ${ RD } $line_number ${ CL } : exit code ${ RD } $exit_code ${ CL } : while executing command ${ YW } $command ${ CL } "
2026-02-12 20:06:02 +01:00
post_update_to_api "failed" " ${ exit_code } "
2025-06-18 22:08:23 +02:00
echo -e "\n $error_message \n"
cleanup_vmid
2022-08-06 15:23:25 -04:00
}
2025-05-07 12:37:46 +02:00
function get_valid_nextid() {
local try_id
try_id = $( pvesh get /cluster/nextid)
while true; do
if [ -f "/etc/pve/qemu-server/ ${ try_id } .conf" ] || [ -f "/etc/pve/lxc/ ${ try_id } .conf" ] ; then
try_id = $(( try_id + 1 ))
continue
fi
if lvs --noheadings -o lv_name | grep -qE "(^|[-_]) ${ try_id } ( $|[-_])" ; then
try_id = $(( try_id + 1 ))
continue
fi
break
done
echo " $try_id "
}
2022-08-06 15:23:25 -04:00
function cleanup_vmid() {
2025-06-18 22:08:23 +02:00
if qm status $VMID & >/dev/null; then
qm stop $VMID & >/dev/null
qm destroy $VMID & >/dev/null
2022-08-06 15:23:25 -04:00
fi
}
2025-06-18 22:08:23 +02:00
2022-08-06 15:23:25 -04:00
function cleanup() {
2026-02-16 17:14:00 +01:00
local exit_code = $?
2022-08-06 15:23:25 -04:00
popd >/dev/null
2026-02-16 17:14:00 +01:00
if [[ " ${ POST_TO_API_DONE :- } " == "true" && " ${ POST_UPDATE_DONE :- } " != "true" ]] ; then
if [[ $exit_code -eq 0 ]] ; then
post_update_to_api "done" "none"
else
post_update_to_api "failed" " $exit_code "
fi
fi
2022-08-06 15:23:25 -04:00
rm -rf $TEMP_DIR
}
2025-06-18 22:08:23 +02:00
2022-08-06 15:23:25 -04:00
TEMP_DIR = $( mktemp -d)
pushd $TEMP_DIR >/dev/null
2025-06-19 07:29:00 +02:00
if whiptail --backtitle "Proxmox VE Helper Scripts" --title "Pimox Homeassistant OS VM" --yesno "This will create a New Pimox Homeassistant OS VM. Proceed?" 10 58; then
2025-06-18 22:08:23 +02:00
:
2022-08-06 15:23:25 -04:00
else
2025-06-18 22:08:23 +02:00
header_info && echo -e " ${ CROSS }${ RD } User exited script ${ CL } \n" && exit
2022-08-06 15:23:25 -04:00
fi
2025-06-18 22:08:23 +02:00
2022-08-06 15:23:25 -04:00
function msg_info() {
2023-03-22 20:48:20 -04:00
local msg = " $1 "
2025-06-18 22:08:23 +02:00
echo -ne " ${ TAB }${ YW }${ HOLD }${ msg }${ HOLD } "
2022-08-06 15:23:25 -04:00
}
2025-06-18 22:08:23 +02:00
2022-08-06 15:23:25 -04:00
function msg_ok() {
2023-03-22 20:48:20 -04:00
local msg = " $1 "
2025-06-18 22:08:23 +02:00
echo -e " ${ BFR }${ CM }${ GN }${ msg }${ CL } "
2022-08-06 15:23:25 -04:00
}
2025-06-18 22:08:23 +02:00
2022-09-29 12:11:55 -04:00
function msg_error() {
2023-03-22 20:48:20 -04:00
local msg = " $1 "
2025-06-18 22:08:23 +02:00
echo -e " ${ BFR }${ CROSS }${ RD }${ msg }${ CL } "
}
function check_root() {
if [[ " $( id -u) " -ne 0 || $( ps -o comm = -p $PPID ) == "sudo" ]] ; then
clear
msg_error "Please run this script as root."
echo -e "\nExiting..."
sleep 2
exit
fi
}
2025-08-06 13:46:07 +02:00
# This function checks the version of Proxmox Virtual Environment (PVE) and exits if the version is not supported.
2026-05-21 19:04:47 +02:00
# Supported: Proxmox VE 8.0.x – 8.9.x, 9.0 and 9.2
2025-07-28 11:00:09 +02:00
pve_check() {
local PVE_VER
PVE_VER = " $( pveversion | awk -F'/' '{print $2}' | awk -F'-' '{print $1}' ) "
2025-08-06 13:46:07 +02:00
# Check for Proxmox VE 8.x: allow 8.0– 8.9
2025-07-28 11:00:09 +02:00
if [[ " $PVE_VER " = ~ ^8\. ([ 0-9] +) ]] ; then
local MINOR = " ${ BASH_REMATCH [1] } "
2025-08-06 13:46:07 +02:00
if (( MINOR < 0 || MINOR > 9)) ; then
2025-07-28 11:00:09 +02:00
msg_error "This version of Proxmox VE is not supported."
2025-08-06 13:46:07 +02:00
msg_error "Supported: Proxmox VE version 8.0 – 8.9"
2026-03-02 10:55:20 +01:00
exit 105
2025-07-28 11:00:09 +02:00
fi
return 0
2025-06-18 22:08:23 +02:00
fi
2025-07-28 11:00:09 +02:00
2026-05-21 19:04:47 +02:00
# Check for Proxmox VE 9.x: allow 9.0 and 9.2
2025-07-28 11:00:09 +02:00
if [[ " $PVE_VER " = ~ ^9\. ([ 0-9] +) ]] ; then
2025-08-06 13:46:07 +02:00
local MINOR = " ${ BASH_REMATCH [1] } "
2026-05-21 19:04:47 +02:00
if (( MINOR < 0 || MINOR > 2)) ; then
2025-11-22 14:35:13 +01:00
msg_error "This version of Proxmox VE is not supported."
2026-05-21 19:04:47 +02:00
msg_error "Supported: Proxmox VE version 9.0 – 9.2"
2026-03-02 10:55:20 +01:00
exit 105
2025-07-28 11:00:09 +02:00
fi
2025-08-06 13:46:07 +02:00
return 0
2025-07-28 11:00:09 +02:00
fi
# All other unsupported versions
msg_error "This version of Proxmox VE is not supported."
2026-05-21 19:04:47 +02:00
msg_error "Supported versions: Proxmox VE 8.0 – 8.x or 9.0 – 9.2"
2026-03-02 10:55:20 +01:00
exit 105
2025-06-18 22:08:23 +02:00
}
function arch_check() {
if [ " $( dpkg --print-architecture) " != "amd64" ] ; then
echo -e "\n ${ INFO }${ YWB } This script will not work with PiMox! \n"
echo -e "\n ${ YWB } Visit https://github.com/asylumexp/Proxmox for ARM64 support. \n"
echo -e "Exiting..."
sleep 2
exit
fi
}
function ssh_check() {
if command -v pveversion >/dev/null 2>& 1; then
if [ -n " ${ SSH_CLIENT :+x } " ] ; then
if whiptail --backtitle "Proxmox VE Helper Scripts" --defaultno --title "SSH DETECTED" --yesno "It's suggested to use the Proxmox shell instead of SSH, since SSH can create issues while gathering variables. Would you like to proceed with using SSH?" 10 62; then
echo "you've been warned"
else
clear
exit
fi
fi
fi
}
function exit-script() {
clear
echo -e "\n ${ CROSS }${ RD } User exited script ${ CL } \n"
exit
2022-09-29 12:11:55 -04:00
}
2022-08-06 15:23:25 -04:00
function default_settings() {
2025-02-10 09:13:09 +01:00
METHOD = "default"
2023-03-22 20:48:20 -04:00
echo -e " ${ DGN } Using HAOS Version: ${ BGN }${ STABLE }${ CL } "
BRANCH = ${ STABLE }
2025-05-08 12:57:27 +02:00
VMID = $( get_valid_nextid)
echo -e " ${ DGN } Using Virtual Machine ID: ${ BGN } $VMID ${ CL } "
2023-03-22 20:48:20 -04:00
echo -e " ${ DGN } Using Hostname: ${ BGN } haos ${ STABLE }${ CL } "
HN = haos${ STABLE }
echo -e " ${ DGN } Allocated Cores: ${ BGN } 2 ${ CL } "
CORE_COUNT = "2"
echo -e " ${ DGN } Allocated RAM: ${ BGN } 4096 ${ CL } "
RAM_SIZE = "4096"
echo -e " ${ DGN } Using Bridge: ${ BGN } vmbr0 ${ CL } "
BRG = "vmbr0"
echo -e " ${ DGN } Using MAC Address: ${ BGN } $GEN_MAC ${ CL } "
MAC = $GEN_MAC
echo -e " ${ DGN } Using VLAN: ${ BGN } Default ${ CL } "
VLAN = ""
echo -e " ${ DGN } Using Interface MTU Size: ${ BGN } Default ${ CL } "
MTU = ""
echo -e " ${ DGN } Start VM when completed: ${ BGN } yes ${ CL } "
START_VM = "yes"
echo -e " ${ BL } Creating a HAOS VM using the above default settings ${ CL } "
2022-08-06 15:23:25 -04:00
}
function advanced_settings() {
2025-02-10 09:13:09 +01:00
METHOD = "advanced"
2023-09-09 05:13:17 -04:00
BRANCH = $( whiptail --backtitle "Proxmox VE Helper Scripts" --title "HAOS VERSION" --radiolist "Choose Version" --cancel-button Exit-Script 10 58 3 \
2023-03-22 20:48:20 -04:00
" $STABLE " "Stable" ON \
" $BETA " "Beta" OFF \
" $DEV " "Dev" OFF \
3>& 1 1>& 2 2>& 3)
exitstatus = $?
if [ $exitstatus = 0 ] ; then echo -e " ${ DGN } Using HAOS Version: ${ BGN } $BRANCH ${ CL } " ; fi
2025-05-08 12:57:27 +02:00
[ -z " ${ VMID :- } " ] && VMID = $( get_valid_nextid)
VMID = $( whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $VMID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>& 1 1>& 2 2>& 3)
2023-03-22 20:48:20 -04:00
exitstatus = $?
if [ -z $VMID ] ; then
2025-05-08 12:57:27 +02:00
VMID = " $VMID "
2023-03-22 20:48:20 -04:00
echo -e " ${ DGN } Virtual Machine: ${ BGN } $VMID ${ CL } "
2023-01-25 10:42:35 -05:00
else
2023-03-22 20:48:20 -04:00
if echo " $USEDID " | egrep -q " $VMID " ; then
2023-01-25 10:42:35 -05:00
echo -e "\n🚨 ${ RD } ID $VMID is already in use ${ CL } \n"
echo -e "Exiting Script \n"
2023-03-22 20:48:20 -04:00
sleep 2
2023-01-25 10:42:35 -05:00
exit
2023-03-22 20:48:20 -04:00
else
if [ $exitstatus = 0 ] ; then echo -e " ${ DGN } Virtual Machine ID: ${ BGN } $VMID ${ CL } " ; fi
fi
fi
2023-09-09 05:13:17 -04:00
VM_NAME = $( whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 haos${ BRANCH } --title "HOSTNAME" --cancel-button Exit-Script 3>& 1 1>& 2 2>& 3)
2023-03-22 20:48:20 -04:00
exitstatus = $?
if [ -z $VM_NAME ] ; then
HN = "haos ${ BRANCH } "
echo -e " ${ DGN } Using Hostname: ${ BGN } $HN ${ CL } "
2023-01-25 10:42:35 -05:00
else
2023-03-22 20:48:20 -04:00
if [ $exitstatus = 0 ] ; then
2026-03-20 13:18:01 +01:00
HN = $( echo " ${ VM_NAME ,, } " | tr -cs 'a-z0-9-' '-' | sed 's/^-//;s/-$//' )
if [ " $HN " != " ${ VM_NAME ,, } " ] ; then
whiptail --backtitle "Proxmox VE Helper Scripts" --title "HOSTNAME ADJUSTED" --msgbox "Invalid characters detected. Hostname has been adjusted to:\n\n $HN " 10 58
fi
2023-03-22 20:48:20 -04:00
echo -e " ${ DGN } Using Hostname: ${ BGN } $HN ${ CL } "
2023-01-25 10:42:35 -05:00
fi
2023-03-22 20:48:20 -04:00
fi
2026-03-20 13:18:01 +01:00
while true; do
CORE_COUNT = $( whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate CPU Cores" 8 58 2 --title "CORE COUNT" --cancel-button Exit-Script 3>& 1 1>& 2 2>& 3)
exitstatus = $?
if [ $exitstatus -ne 0 ] ; then exit-script; fi
if [ -z " $CORE_COUNT " ] ; then CORE_COUNT = "2" ; fi
if [[ " $CORE_COUNT " = ~ ^[ 1-9][ 0-9] *$ ]] ; then
echo -e " ${ DGN } Allocated Cores: ${ BGN } $CORE_COUNT ${ CL } "
break
fi
whiptail --backtitle "Proxmox VE Helper Scripts" --title "INVALID INPUT" --msgbox "CPU Cores must be a positive integer (e.g., 2)." 8 58
done
while true; do
RAM_SIZE = $( whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 4096 --title "RAM" --cancel-button Exit-Script 3>& 1 1>& 2 2>& 3)
exitstatus = $?
if [ $exitstatus -ne 0 ] ; then exit-script; fi
if [ -z " $RAM_SIZE " ] ; then RAM_SIZE = "4096" ; fi
if [[ " $RAM_SIZE " = ~ ^[ 1-9][ 0-9] *$ ]] ; then
echo -e " ${ DGN } Allocated RAM: ${ BGN } $RAM_SIZE ${ CL } "
break
fi
whiptail --backtitle "Proxmox VE Helper Scripts" --title "INVALID INPUT" --msgbox "RAM Size must be a positive integer in MiB (e.g., 4096)." 8 58
done
2023-09-09 05:13:17 -04:00
BRG = $( whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>& 1 1>& 2 2>& 3)
2023-03-22 20:48:20 -04:00
exitstatus = $?
if [ -z $BRG ] ; then
BRG = "vmbr0"
echo -e " ${ DGN } Using Bridge: ${ BGN } $BRG ${ CL } "
else
if [ $exitstatus = 0 ] ; then echo -e " ${ DGN } Using Bridge: ${ BGN } $BRG ${ CL } " ; fi
fi
2026-03-20 13:18:01 +01:00
while true; do
MAC1 = $( whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a MAC Address" 8 58 $GEN_MAC --title "MAC ADDRESS" --cancel-button Exit-Script 3>& 1 1>& 2 2>& 3)
exitstatus = $?
if [ $exitstatus -ne 0 ] ; then exit-script; fi
if [ -z " $MAC1 " ] ; then
MAC = " $GEN_MAC "
echo -e " ${ DGN } Using MAC Address: ${ BGN } $MAC ${ CL } "
break
fi
if [[ " $MAC1 " = ~ ^([ 0-9A-Fa-f]{ 2} :){ 5}[ 0-9A-Fa-f]{ 2} $ ]] ; then
2023-03-22 20:48:20 -04:00
MAC = " $MAC1 "
echo -e " ${ DGN } Using MAC Address: ${ BGN } $MAC1 ${ CL } "
2026-03-20 13:18:01 +01:00
break
2023-03-22 20:48:20 -04:00
fi
2026-03-20 13:18:01 +01:00
whiptail --backtitle "Proxmox VE Helper Scripts" --title "INVALID INPUT" --msgbox "Invalid MAC address format. Use XX:XX:XX:XX:XX:XX (e.g., AA:BB:CC:DD:EE:FF)." 8 58
done
while true; do
VLAN1 = $( whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>& 1 1>& 2 2>& 3)
exitstatus = $?
if [ $exitstatus -ne 0 ] ; then exit-script; fi
if [ -z " $VLAN1 " ] ; then
VLAN1 = "Default"
VLAN = ""
2023-03-22 20:48:20 -04:00
echo -e " ${ DGN } Using Vlan: ${ BGN } $VLAN1 ${ CL } "
2026-03-20 13:18:01 +01:00
break
fi
if [[ " $VLAN1 " = ~ ^[ 0-9] +$ ]] && [ " $VLAN1 " -ge 1 ] && [ " $VLAN1 " -le 4094 ] ; then
2023-03-22 20:48:20 -04:00
VLAN = ",tag= $VLAN1 "
echo -e " ${ DGN } Using Vlan: ${ BGN } $VLAN1 ${ CL } "
2026-03-20 13:18:01 +01:00
break
2023-03-22 20:48:20 -04:00
fi
2026-03-20 13:18:01 +01:00
whiptail --backtitle "Proxmox VE Helper Scripts" --title "INVALID INPUT" --msgbox "VLAN must be a number between 1 and 4094, or leave blank for default." 8 58
done
while true; do
MTU1 = $( whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" --cancel-button Exit-Script 3>& 1 1>& 2 2>& 3)
exitstatus = $?
if [ $exitstatus -ne 0 ] ; then exit-script; fi
if [ -z " $MTU1 " ] ; then
MTU1 = "Default"
MTU = ""
2023-03-22 20:48:20 -04:00
echo -e " ${ DGN } Using Interface MTU Size: ${ BGN } $MTU1 ${ CL } "
2026-03-20 13:18:01 +01:00
break
fi
if [[ " $MTU1 " = ~ ^[ 0-9] +$ ]] && [ " $MTU1 " -ge 576 ] && [ " $MTU1 " -le 65520 ] ; then
2023-03-22 20:48:20 -04:00
MTU = ",mtu= $MTU1 "
echo -e " ${ DGN } Using Interface MTU Size: ${ BGN } $MTU1 ${ CL } "
2026-03-20 13:18:01 +01:00
break
2023-03-22 20:48:20 -04:00
fi
2026-03-20 13:18:01 +01:00
whiptail --backtitle "Proxmox VE Helper Scripts" --title "INVALID INPUT" --msgbox "MTU Size must be a number between 576 and 65520, or leave blank for default." 8 58
done
2023-09-09 05:13:17 -04:00
if ( whiptail --backtitle "Proxmox VE Helper Scripts" --title "START VIRTUAL MACHINE" --yesno "Start VM when completed?" 10 58) ; then
2022-08-06 15:23:25 -04:00
echo -e " ${ DGN } Start VM when completed: ${ BGN } yes ${ CL } "
START_VM = "yes"
2023-03-22 20:48:20 -04:00
else
2022-08-06 15:23:25 -04:00
echo -e " ${ DGN } Start VM when completed: ${ BGN } no ${ CL } "
START_VM = "no"
2023-03-22 20:48:20 -04:00
fi
2023-09-09 05:13:17 -04:00
if ( whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create HAOS ${ BRANCH } VM?" --no-button Do-Over 10 58) ; then
2022-08-06 15:23:25 -04:00
echo -e " ${ RD } Creating a HAOS VM using the above advanced settings ${ CL } "
2023-03-22 20:48:20 -04:00
else
clear
header_info
echo -e " ${ RD } Using Advanced Settings ${ CL } "
advanced_settings
fi
2022-08-06 15:23:25 -04:00
}
2023-01-25 10:42:35 -05:00
function START_SCRIPT() {
2023-09-09 05:13:17 -04:00
if ( whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58) ; then
2023-03-22 20:48:20 -04:00
clear
header_info
echo -e " ${ BL } Using Default Settings ${ CL } "
default_settings
else
clear
header_info
echo -e " ${ RD } Using Advanced Settings ${ CL } "
advanced_settings
fi
2022-08-06 15:23:25 -04:00
}
2023-01-25 10:42:35 -05:00
ARCH_CHECK
START_SCRIPT
2025-02-10 09:13:09 +01:00
post_to_api_vm
2022-08-06 15:23:25 -04:00
while read -r line; do
TAG = $( echo $line | awk '{print $1}' )
TYPE = $( echo $line | awk '{printf "%-10s", $2}' )
FREE = $( echo $line | numfmt --field 4-6 --from-unit= K --to= iec --format %.2f | awk '{printf( "%9sB", $6)}' )
ITEM = " Type: $TYPE Free: $FREE "
OFFSET = 2
if [[ $(( ${# ITEM } + $OFFSET )) -gt ${ MSG_MAX_LENGTH :- } ]] ; then
MSG_MAX_LENGTH = $(( ${# ITEM } + $OFFSET ))
fi
2023-03-22 20:48:20 -04:00
STORAGE_MENU +=( " $TAG " " $ITEM " "OFF" )
2022-08-06 15:23:25 -04:00
done < <( pvesm status -content images | awk 'NR>1' )
2023-03-22 20:48:20 -04:00
if [ $(( ${# STORAGE_MENU [@] } / 3 )) -eq 0 ] ; then
2022-08-06 15:23:25 -04:00
echo -e "'Disk image' needs to be selected for at least one storage location."
die "Unable to detect valid storage location."
2023-03-22 20:48:20 -04:00
elif [ $(( ${# STORAGE_MENU [@] } / 3 )) -eq 1 ] ; then
2022-08-06 15:23:25 -04:00
STORAGE = ${ STORAGE_MENU [0] }
else
while [ -z " ${ STORAGE :+x } " ] ; do
2023-09-09 05:13:17 -04:00
STORAGE = $( whiptail --backtitle "Proxmox VE Helper Scripts" --title "Storage Pools" --radiolist \
2025-04-17 02:49:55 -04:00
"Which storage pool would you like to use for the HAOS VM?\n\n" \
2023-03-22 20:48:20 -04:00
16 $(( $MSG_MAX_LENGTH + 23 )) 6 \
2025-04-15 15:20:46 +02:00
" ${ STORAGE_MENU [@] } " 3>& 1 1>& 2 2>& 3)
2022-08-06 15:23:25 -04:00
done
fi
msg_ok "Using ${ CL }${ BL } $STORAGE ${ CL } ${ GN } for Storage Location."
msg_ok "Virtual Machine ID is ${ CL }${ BL } $VMID ${ CL } ."
msg_info "Getting URL for Home Assistant ${ BRANCH } Disk Image"
URL = https://github.com/home-assistant/operating-system/releases/download/${ BRANCH } /haos_generic-aarch64-${ BRANCH } .qcow2.xz
sleep 2
msg_ok " ${ CL }${ BL }${ URL }${ CL } "
2025-04-03 16:01:23 +02:00
curl -f#SL -o " $( basename " $URL " ) " " $URL "
2022-08-06 15:23:25 -04:00
echo -en "\e[1A\e[0K"
FILE = $( basename $URL )
msg_ok "Downloaded ${ CL }${ BL } haos_generic-aarch64- ${ BRANCH } .qcow2.xz ${ CL } "
msg_info "Extracting Disk Image"
unxz $FILE
STORAGE_TYPE = $( pvesm status -storage $STORAGE | awk 'NR>1 {print $2}' )
case $STORAGE_TYPE in
2023-03-22 20:48:20 -04:00
nfs | dir)
DISK_EXT = ".qcow2"
DISK_REF = " $VMID /"
DISK_IMPORT = "-format qcow2"
;;
2026-02-12 20:06:02 +01:00
*)
DISK_EXT = ""
DISK_REF = ""
DISK_IMPORT = "-format raw"
;;
2022-08-06 15:23:25 -04:00
esac
for i in { 0,1} ; do
disk = "DISK $i "
eval DISK${ i } = vm-${ VMID } -disk-${ i }${ DISK_EXT :- }
eval DISK${ i } _REF = ${ STORAGE } :${ DISK_REF :- }${ !disk }
done
msg_ok "Extracted Disk Image"
msg_info "Creating HAOS VM"
2023-01-25 10:42:35 -05:00
qm create $VMID -bios ovmf -cores $CORE_COUNT -memory $RAM_SIZE -name $HN \
-net0 virtio,bridge= $BRG ,macaddr= $MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci
2022-08-06 15:51:17 -04:00
pvesm alloc $STORAGE $VMID $DISK0 64M 1>& /dev/null
2022-08-06 15:23:25 -04:00
qm importdisk $VMID ${ FILE %.* } $STORAGE ${ DISK_IMPORT :- } 1>& /dev/null
qm set $VMID \
2022-08-06 15:51:17 -04:00
-efidisk0 ${ DISK0_REF } ,efitype= 4m,size= 64M \
-scsi0 ${ DISK1_REF } ,size= 32G >/dev/null
2022-08-06 15:23:25 -04:00
qm set $VMID \
2025-06-18 22:08:23 +02:00
-boot order = scsi0 >/dev/null
DESCRIPTION = $(
cat <<EOF
<div align='center'>
2026-03-25 17:48:03 +01:00
<a href='https://community-scripts.org' target='_blank' rel='noopener noreferrer'>
2025-06-18 22:08:23 +02:00
<img src='https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/images/logo-81x112.png' alt='Logo' style='width:81px;height:112px;'/>
</a>
2025-06-22 21:40:54 +02:00
<h2 style='font-size: 24px; margin: 20px 0;'>Homeassistant VM</h2>
2023-11-27 09:48:44 -05:00
2025-06-18 22:08:23 +02:00
<p style='margin: 16px 0;'>
<a href='https://ko-fi.com/community_scripts' target='_blank' rel='noopener noreferrer'>
<img src='https://img.shields.io/badge/☕-Buy us a coffee-blue' alt='spend Coffee' />
</a>
</p>
<span style='margin: 0 10px;'>
<i class="fa fa-github fa-fw" style="color: #f5f5f5;"></i>
<a href='https://github.com/community-scripts/ProxmoxVE' target='_blank' rel='noopener noreferrer' style='text-decoration: none; color: #00617f;'>GitHub</a>
</span>
<span style='margin: 0 10px;'>
<i class="fa fa-comments fa-fw" style="color: #f5f5f5;"></i>
<a href='https://github.com/community-scripts/ProxmoxVE/discussions' target='_blank' rel='noopener noreferrer' style='text-decoration: none; color: #00617f;'>Discussions</a>
</span>
<span style='margin: 0 10px;'>
<i class="fa fa-exclamation-circle fa-fw" style="color: #f5f5f5;"></i>
<a href='https://github.com/community-scripts/ProxmoxVE/issues' target='_blank' rel='noopener noreferrer' style='text-decoration: none; color: #00617f;'>Issues</a>
</span>
</div>
EOF
)
2026-01-08 15:10:57 +01:00
qm set $VMID -description " $DESCRIPTION " >/dev/null
2025-06-18 22:08:23 +02:00
if [ -n " $DISK_SIZE " ] ; then
msg_info "Resizing disk to $DISK_SIZE GB"
qm resize $VMID scsi0 ${ DISK_SIZE } >/dev/null
else
msg_info "Using default disk size of $DEFAULT_DISK_SIZE GB"
qm resize $VMID scsi0 ${ DEFAULT_DISK_SIZE } >/dev/null
fi
2023-11-27 09:48:44 -05:00
2022-08-06 15:23:25 -04:00
msg_ok "Created HAOS VM ${ CL }${ BL } ( ${ HN } )"
if [ " $START_VM " == "yes" ] ; then
2023-03-22 20:48:20 -04:00
msg_info "Starting Home Assistant OS VM"
qm start $VMID
msg_ok "Started Home Assistant OS VM"
2022-08-06 15:23:25 -04:00
fi
2025-02-10 09:13:09 +01:00
post_update_to_api "done" "none"
2026-01-06 22:57:40 +01:00
msg_ok "Completed successfully!\n"