From 404ae5dbcff6d5d737e4db4d3b2e59820ec1d893 Mon Sep 17 00:00:00 2001 From: CanbiZ Date: Wed, 9 Apr 2025 18:50:27 +0200 Subject: [PATCH] fix pvecheck --- vm/debian-vm.sh | 70 ++++++++++++++--------------- vm/docker-vm.sh | 72 +++++++++++++++--------------- vm/haos-vm.sh | 72 +++++++++++++++--------------- vm/mikrotik-routeros.sh | 48 ++++++++++---------- vm/nextcloud-vm.sh | 70 ++++++++++++++--------------- vm/openwrt.sh | 98 ++++++++++++++++++++--------------------- vm/opnsense-vm.sh | 2 +- vm/ubuntu2204-vm.sh | 72 +++++++++++++++--------------- vm/ubuntu2410-vm.sh | 72 +++++++++++++++--------------- 9 files changed, 288 insertions(+), 288 deletions(-) diff --git a/vm/debian-vm.sh b/vm/debian-vm.sh index cc89265c0..9a1c1c8bb 100644 --- a/vm/debian-vm.sh +++ b/vm/debian-vm.sh @@ -76,20 +76,20 @@ function error_handler() { } function cleanup_vmid() { - if qm status $VMID &>/dev/null; then - qm stop $VMID &>/dev/null - qm destroy $VMID &>/dev/null + if qm status "$VMID" &>/dev/null; then + qm stop "$VMID" &>/dev/null + qm destroy "$VMID" &>/dev/null fi } function cleanup() { popd >/dev/null post_update_to_api "done" "none" - rm -rf $TEMP_DIR + rm -rf "$TEMP_DIR" } TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null +pushd "$TEMP_DIR" >/dev/null if whiptail --backtitle "Proxmox VE Helper Scripts" --title "Debian 12 VM" --yesno "This will create a New Debian 12 VM. Proceed?" 10 58; then : else @@ -122,7 +122,7 @@ function check_root() { } function pve_check() { - if ! pveversion | grep -Eq "pve-manager/8\.[1-3](\.[0-9]+)*"; then + if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then msg_error "${CROSS}${RD}This version of Proxmox Virtual Environment is not supported" echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." echo -e "Exiting..." @@ -195,7 +195,7 @@ function default_settings() { function advanced_settings() { METHOD="advanced" while true; do - if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 "$NEXTID" --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then if [ -z "$VMID" ]; then VMID="$NEXTID" fi @@ -215,7 +215,7 @@ function advanced_settings() { "i440fx" "Machine i440fx" ON \ "q35" "Machine q35" OFF \ 3>&1 1>&2 2>&3); then - if [ $MACH = q35 ]; then + if [ "$MACH" = q35 ]; then echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}$MACH${CL}" FORMAT="" MACHINE=" -machine q35" @@ -247,7 +247,7 @@ function advanced_settings() { "0" "None (Default)" ON \ "1" "Write Through" OFF \ 3>&1 1>&2 2>&3); then - if [ $DISK_CACHE = "1" ]; then + if [ "$DISK_CACHE" = "1" ]; then echo -e "${DISKSIZE}${BOLD}${DGN}Disk Cache: ${BGN}Write Through${CL}" DISK_CACHE="cache=writethrough," else @@ -259,11 +259,11 @@ function advanced_settings() { fi if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 debian --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $VM_NAME ]; then + if [ -z "$VM_NAME" ]; then HN="debian" echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}$HN${CL}" else - HN=$(echo ${VM_NAME,,} | tr -d ' ') + HN=$(echo "${VM_NAME,,}" | tr -d ' ') echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}$HN${CL}" fi else @@ -274,7 +274,7 @@ function advanced_settings() { "0" "KVM64 (Default)" ON \ "1" "Host" OFF \ 3>&1 1>&2 2>&3); then - if [ $CPU_TYPE1 = "1" ]; then + if [ "$CPU_TYPE1" = "1" ]; then echo -e "${OS}${BOLD}${DGN}CPU Model: ${BGN}Host${CL}" CPU_TYPE=" -cpu host" else @@ -286,7 +286,7 @@ function advanced_settings() { fi if 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); then - if [ -z $CORE_COUNT ]; then + if [ -z "$CORE_COUNT" ]; then CORE_COUNT="2" echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}$CORE_COUNT${CL}" else @@ -297,7 +297,7 @@ function advanced_settings() { fi if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 2048 --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $RAM_SIZE ]; then + if [ -z "$RAM_SIZE" ]; then RAM_SIZE="2048" echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}$RAM_SIZE${CL}" else @@ -308,7 +308,7 @@ function advanced_settings() { fi if 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); then - if [ -z $BRG ]; then + if [ -z "$BRG" ]; then BRG="vmbr0" echo -e "${BRIDGE}${BOLD}${DGN}Bridge: ${BGN}$BRG${CL}" else @@ -318,8 +318,8 @@ function advanced_settings() { exit-script fi - if 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); then - if [ -z $MAC1 ]; then + if 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); then + if [ -z "$MAC1" ]; then MAC="$GEN_MAC" echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}$MAC${CL}" else @@ -331,7 +331,7 @@ function advanced_settings() { fi if 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); then - if [ -z $VLAN1 ]; then + if [ -z "$VLAN1" ]; then VLAN1="Default" VLAN="" echo -e "${VLANTAG}${BOLD}${DGN}VLAN: ${BGN}$VLAN1${CL}" @@ -344,7 +344,7 @@ function advanced_settings() { fi if 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); then - if [ -z $MTU1 ]; then + if [ -z "$MTU1" ]; then MTU1="Default" MTU="" echo -e "${DEFAULT}${BOLD}${DGN}Interface MTU Size: ${BGN}$MTU1${CL}" @@ -395,9 +395,9 @@ post_to_api_vm msg_info "Validating Storage" 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)}') + 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 @@ -430,7 +430,7 @@ echo -en "\e[1A\e[0K" FILE=$(basename $URL) msg_ok "Downloaded ${CL}${BL}${FILE}${CL}" -STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') +STORAGE_TYPE=$(pvesm status -storage "$STORAGE" | awk 'NR>1 {print $2}') case $STORAGE_TYPE in nfs | dir) DISK_EXT=".qcow2" @@ -448,18 +448,18 @@ btrfs) 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} + eval DISK"${i}"=vm-"${VMID}"-disk-"${i}"${DISK_EXT:-} + eval DISK"${i}"_REF="${STORAGE}":"${DISK_REF:-}"${!disk} done msg_info "Creating a Debian 12 VM" -qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios ovmf${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \ - -name $HN -tags community-script -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null -qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null -qm set $VMID \ - -efidisk0 ${DISK0_REF}${FORMAT} \ - -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=${DISK_SIZE} \ +qm create "$VMID" -agent 1"${MACHINE}" -tablet 0 -localtime 1 -bios ovmf"${CPU_TYPE}" -cores "$CORE_COUNT" -memory "$RAM_SIZE" \ + -name "$HN" -tags community-script -net0 virtio,bridge="$BRG",macaddr="$MAC"$VLAN"$MTU" -onboot 1 -ostype l26 -scsihw virtio-scsi-pci +pvesm alloc "$STORAGE" "$VMID" "$DISK0" 4M 1>&/dev/null +qm importdisk "$VMID" "${FILE}" "$STORAGE" "${DISK_IMPORT:-}" 1>&/dev/null +qm set "$VMID" \ + -efidisk0 "${DISK0_REF}"${FORMAT} \ + -scsi0 "${DISK1_REF}",${DISK_CACHE}${THIN}size="${DISK_SIZE}" \ -boot order=scsi0 \ -serial0 socket >/dev/null DESCRIPTION=$( @@ -495,16 +495,16 @@ EOF qm set "$VMID" -description "$DESCRIPTION" >/dev/null if [ -n "$DISK_SIZE" ]; then msg_info "Resizing disk to $DISK_SIZE GB" - qm resize $VMID scsi0 ${DISK_SIZE} >/dev/null + 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 + qm resize "$VMID" scsi0 "${DEFAULT_DISK_SIZE}" >/dev/null fi msg_ok "Created a Debian 12 VM ${CL}${BL}(${HN})" if [ "$START_VM" == "yes" ]; then msg_info "Starting Debian 12 VM" - qm start $VMID + qm start "$VMID" msg_ok "Started Debian 12 VM" fi diff --git a/vm/docker-vm.sh b/vm/docker-vm.sh index 4bd6bc8e4..71ed3e5eb 100644 --- a/vm/docker-vm.sh +++ b/vm/docker-vm.sh @@ -57,19 +57,19 @@ function error_handler() { } function cleanup_vmid() { - if qm status $VMID &>/dev/null; then - qm stop $VMID &>/dev/null - qm destroy $VMID &>/dev/null + if qm status "$VMID" &>/dev/null; then + qm stop "$VMID" &>/dev/null + qm destroy "$VMID" &>/dev/null fi } function cleanup() { popd >/dev/null - rm -rf $TEMP_DIR + rm -rf "$TEMP_DIR" } TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null +pushd "$TEMP_DIR" >/dev/null if whiptail --backtitle "Proxmox VE Helper Scripts" --title "Docker VM" --yesno "This will create a New Docker VM. Proceed?" 10 58; then : else @@ -102,7 +102,7 @@ function check_root() { } function pve_check() { - if ! pveversion | grep -Eq "pve-manager/8\.[1-3](\.[0-9]+)*"; then + if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then msg_error "This version of Proxmox Virtual Environment is not supported" echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." echo -e "Exiting..." @@ -174,7 +174,7 @@ function default_settings() { function advanced_settings() { METHOD="advanced" while true; do - if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 "$NEXTID" --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then if [ -z "$VMID" ]; then VMID="$NEXTID" fi @@ -194,7 +194,7 @@ function advanced_settings() { "i440fx" "Machine i440fx" ON \ "q35" "Machine q35" OFF \ 3>&1 1>&2 2>&3); then - if [ $MACH = q35 ]; then + if [ "$MACH" = q35 ]; then echo -e "${DGN}Using Machine Type: ${BGN}$MACH${CL}" FORMAT="" MACHINE=" -machine q35" @@ -211,7 +211,7 @@ function advanced_settings() { "0" "None (Default)" ON \ "1" "Write Through" OFF \ 3>&1 1>&2 2>&3); then - if [ $DISK_CACHE = "1" ]; then + if [ "$DISK_CACHE" = "1" ]; then echo -e "${DGN}Using Disk Cache: ${BGN}Write Through${CL}" DISK_CACHE="cache=writethrough," else @@ -223,11 +223,11 @@ function advanced_settings() { fi if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 docker --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $VM_NAME ]; then + if [ -z "$VM_NAME" ]; then HN="docker" echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" else - HN=$(echo ${VM_NAME,,} | tr -d ' ') + HN=$(echo "${VM_NAME,,}" | tr -d ' ') echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" fi else @@ -238,7 +238,7 @@ function advanced_settings() { "0" "KVM64 (Default)" ON \ "1" "Host" OFF \ 3>&1 1>&2 2>&3); then - if [ $CPU_TYPE1 = "1" ]; then + if [ "$CPU_TYPE1" = "1" ]; then echo -e "${DGN}Using CPU Model: ${BGN}Host${CL}" CPU_TYPE=" -cpu host" else @@ -250,7 +250,7 @@ function advanced_settings() { fi if 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); then - if [ -z $CORE_COUNT ]; then + if [ -z "$CORE_COUNT" ]; then CORE_COUNT="2" echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" else @@ -261,7 +261,7 @@ function advanced_settings() { fi if 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); then - if [ -z $RAM_SIZE ]; then + if [ -z "$RAM_SIZE" ]; then RAM_SIZE="4096" echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" else @@ -272,7 +272,7 @@ function advanced_settings() { fi if 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); then - if [ -z $BRG ]; then + if [ -z "$BRG" ]; then BRG="vmbr0" echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" else @@ -282,8 +282,8 @@ function advanced_settings() { exit-script fi - if 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); then - if [ -z $MAC1 ]; then + if 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); then + if [ -z "$MAC1" ]; then MAC="$GEN_MAC" echo -e "${DGN}Using MAC Address: ${BGN}$MAC${CL}" else @@ -295,7 +295,7 @@ function advanced_settings() { fi if 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); then - if [ -z $VLAN1 ]; then + if [ -z "$VLAN1" ]; then VLAN1="Default" VLAN="" echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" @@ -308,7 +308,7 @@ function advanced_settings() { fi if 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); then - if [ -z $MTU1 ]; then + if [ -z "$MTU1" ]; then MTU1="Default" MTU="" echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" @@ -358,9 +358,9 @@ post_to_api_vm msg_info "Validating Storage" 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)}') + 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 @@ -390,10 +390,10 @@ sleep 2 msg_ok "${CL}${BL}${URL}${CL}" curl -f#SL -o "$(basename "$URL")" "$URL" echo -en "\e[1A\e[0K" -FILE=$(basename $URL) +FILE=$(basename "$URL") msg_ok "Downloaded ${CL}${BL}${FILE}${CL}" -STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') +STORAGE_TYPE=$(pvesm status -storage "$STORAGE" | awk 'NR>1 {print $2}') case $STORAGE_TYPE in nfs | dir) DISK_EXT=".qcow2" @@ -411,8 +411,8 @@ btrfs) 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} + eval DISK"${i}"=vm-"${VMID}"-disk-"${i}"${DISK_EXT:-} + eval DISK"${i}"_REF="${STORAGE}":"${DISK_REF:-}"${!disk} done msg_info "Installing Pre-Requisite libguestfs-tools onto Host" @@ -429,17 +429,17 @@ virt-customize -q -a "${FILE}" --install qemu-guest-agent,apt-transport-https,ca msg_ok "Added Docker and Docker Compose Plugin to Debian 12 Qcow2 Disk Image successfully" msg_info "Creating a Docker VM" -qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios ovmf${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \ - -name $HN -tags community-script,debian12,docker -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null -qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null -qm set $VMID \ - -efidisk0 ${DISK0_REF}${FORMAT} \ - -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=2G \ +qm create "$VMID" -agent 1"${MACHINE}" -tablet 0 -localtime 1 -bios ovmf"${CPU_TYPE}" -cores "$CORE_COUNT" -memory "$RAM_SIZE" \ + -name "$HN" -tags community-script,debian12,docker -net0 virtio,bridge="$BRG",macaddr="$MAC"$VLAN"$MTU" -onboot 1 -ostype l26 -scsihw virtio-scsi-pci +pvesm alloc "$STORAGE" "$VMID" "$DISK0" 4M 1>&/dev/null +qm importdisk "$VMID" "${FILE}" "$STORAGE" "${DISK_IMPORT:-}" 1>&/dev/null +qm set "$VMID" \ + -efidisk0 "${DISK0_REF}"${FORMAT} \ + -scsi0 "${DISK1_REF}",${DISK_CACHE}${THIN}size=2G \ -boot order=scsi0 \ -serial0 socket >/dev/null -qm resize $VMID scsi0 8G >/dev/null -qm set $VMID --agent enabled=1 >/dev/null +qm resize "$VMID" scsi0 8G >/dev/null +qm set "$VMID" --agent enabled=1 >/dev/null DESCRIPTION=$( cat </dev/null msg_ok "Created a Docker VM ${CL}${BL}(${HN})" if [ "$START_VM" == "yes" ]; then msg_info "Starting Docker VM" - qm start $VMID + qm start "$VMID" msg_ok "Started Docker VM" fi post_update_to_api "done" "none" diff --git a/vm/haos-vm.sh b/vm/haos-vm.sh index 0f7bb0744..02f4b72ce 100644 --- a/vm/haos-vm.sh +++ b/vm/haos-vm.sh @@ -66,19 +66,19 @@ function error_handler() { } function cleanup_vmid() { - if qm status $VMID &>/dev/null; then - qm stop $VMID &>/dev/null - qm destroy $VMID &>/dev/null + if qm status "$VMID" &>/dev/null; then + qm stop "$VMID" &>/dev/null + qm destroy "$VMID" &>/dev/null fi } function cleanup() { popd >/dev/null - rm -rf $TEMP_DIR + rm -rf "$TEMP_DIR" } TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null +pushd "$TEMP_DIR" >/dev/null if whiptail --backtitle "Proxmox VE Helper Scripts" --title "HOME ASSISTANT OS VM" --yesno "This will create a New Home Assistant OS VM. Proceed?" 10 58; then : else @@ -127,7 +127,7 @@ function check_root() { } function pve_check() { - if ! pveversion | grep -Eq "pve-manager/8\.[1-3](\.[0-9]+)*"; then + if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then msg_error "This version of Proxmox Virtual Environment is not supported" echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." echo -e "Exiting..." @@ -211,7 +211,7 @@ function advanced_settings() { fi while true; do - if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 "$NEXTID" --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then if [ -z "$VMID" ]; then VMID="$NEXTID" fi @@ -231,7 +231,7 @@ function advanced_settings() { "i440fx" "Machine i440fx" ON \ "q35" "Machine q35" OFF \ 3>&1 1>&2 2>&3); then - if [ $MACH = q35 ]; then + if [ "$MACH" = q35 ]; then echo -e "${DGN}Using Machine Type: ${BGN}$MACH${CL}" FORMAT="" MACHINE=" -machine q35" @@ -248,7 +248,7 @@ function advanced_settings() { "0" "None" OFF \ "1" "Write Through (Default)" ON \ 3>&1 1>&2 2>&3); then - if [ $DISK_CACHE1 = "1" ]; then + if [ "$DISK_CACHE1" = "1" ]; then echo -e "${DGN}Using Disk Cache: ${BGN}Write Through${CL}" DISK_CACHE="cache=writethrough," else @@ -259,12 +259,12 @@ function advanced_settings() { exit-script fi - if 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); then - if [ -z $VM_NAME ]; then + if 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); then + if [ -z "$VM_NAME" ]; then HN="haos${BRANCH}" echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" else - HN=$(echo ${VM_NAME,,} | tr -d ' ') + HN=$(echo "${VM_NAME,,}" | tr -d ' ') echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" fi else @@ -275,7 +275,7 @@ function advanced_settings() { "0" "KVM64" OFF \ "1" "Host (Default)" ON \ 3>&1 1>&2 2>&3); then - if [ $CPU_TYPE1 = "1" ]; then + if [ "$CPU_TYPE1" = "1" ]; then echo -e "${DGN}Using CPU Model: ${BGN}Host${CL}" CPU_TYPE=" -cpu host" else @@ -287,7 +287,7 @@ function advanced_settings() { fi if 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); then - if [ -z $CORE_COUNT ]; then + if [ -z "$CORE_COUNT" ]; then CORE_COUNT="2" echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" else @@ -298,7 +298,7 @@ function advanced_settings() { fi if 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); then - if [ -z $RAM_SIZE ]; then + if [ -z "$RAM_SIZE" ]; then RAM_SIZE="4096" echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" else @@ -309,7 +309,7 @@ function advanced_settings() { fi if 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); then - if [ -z $BRG ]; then + if [ -z "$BRG" ]; then BRG="vmbr0" echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" else @@ -319,8 +319,8 @@ function advanced_settings() { exit-script fi - if 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); then - if [ -z $MAC1 ]; then + if 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); then + if [ -z "$MAC1" ]; then MAC="$GEN_MAC" echo -e "${DGN}Using MAC Address: ${BGN}$MAC${CL}" else @@ -332,7 +332,7 @@ function advanced_settings() { fi if 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); then - if [ -z $VLAN1 ]; then + if [ -z "$VLAN1" ]; then VLAN1="Default" VLAN="" echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" @@ -345,7 +345,7 @@ function advanced_settings() { fi if 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); then - if [ -z $MTU1 ]; then + if [ -z "$MTU1" ]; then MTU1="Default" MTU="" echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" @@ -396,9 +396,9 @@ post_to_api_vm msg_info "Validating Storage" 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)}') + 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 @@ -434,11 +434,11 @@ sleep 2 msg_ok "${CL}${BL}${URL}${CL}" curl -f#SL -o "$(basename "$URL")" "$URL" echo -en "\e[1A\e[0K" -FILE=$(basename $URL) +FILE=$(basename "$URL") msg_ok "Downloaded ${CL}${BL}haos_ova-${BRANCH}.qcow2.xz${CL}" msg_info "Extracting KVM Disk Image" -unxz $FILE -STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') +unxz "$FILE" +STORAGE_TYPE=$(pvesm status -storage "$STORAGE" | awk 'NR>1 {print $2}') case $STORAGE_TYPE in nfs | dir) DISK_EXT=".raw" @@ -456,18 +456,18 @@ btrfs | local-zfs) 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} + eval DISK"${i}"=vm-"${VMID}"-disk-"${i}"${DISK_EXT:-} + eval DISK"${i}"_REF="${STORAGE}":"${DISK_REF:-}"${!disk} done msg_ok "Extracted KVM Disk Image" msg_info "Creating HAOS VM" -qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios ovmf${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \ - -name $HN -tags community-script -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null -qm importdisk $VMID ${FILE%.*} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null -qm set $VMID \ - -efidisk0 ${DISK0_REF}${FORMAT} \ - -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=32G \ +qm create "$VMID" -agent 1"${MACHINE}" -tablet 0 -localtime 1 -bios ovmf"${CPU_TYPE}" -cores "$CORE_COUNT" -memory "$RAM_SIZE" \ + -name "$HN" -tags community-script -net0 virtio,bridge="$BRG",macaddr="$MAC"$VLAN"$MTU" -onboot 1 -ostype l26 -scsihw virtio-scsi-pci +pvesm alloc "$STORAGE" "$VMID" "$DISK0" 4M 1>&/dev/null +qm importdisk "$VMID" "${FILE%.*}" "$STORAGE" "${DISK_IMPORT:-}" 1>&/dev/null +qm set "$VMID" \ + -efidisk0 "${DISK0_REF}"${FORMAT} \ + -scsi0 "${DISK1_REF}",${DISK_CACHE}${THIN}size=32G \ -boot order=scsi0 \ -description "
@@ -478,7 +478,7 @@ qm set $VMID \ msg_ok "Created HAOS VM ${CL}${BL}(${HN})" if [ "$START_VM" == "yes" ]; then msg_info "Starting Home Assistant OS VM" - qm start $VMID + qm start "$VMID" msg_ok "Started Home Assistant OS VM" fi post_update_to_api "done" "none" diff --git a/vm/mikrotik-routeros.sh b/vm/mikrotik-routeros.sh index e2d437664..32b2a3bb1 100644 --- a/vm/mikrotik-routeros.sh +++ b/vm/mikrotik-routeros.sh @@ -57,24 +57,24 @@ function error_exit() { local msg="${1:-$reason}" local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" echo -e "$flag $msg" 1>&2 - [ ! -z ${VMID-} ] && cleanup_vmid - exit $EXIT + [ ! -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 + if $(qm status "$VMID" &>/dev/null); then + if [ "$(qm status "$VMID" | awk '{print $2}')" == "running" ]; then + qm stop "$VMID" fi - qm destroy $VMID + qm destroy "$VMID" fi } function cleanup() { popd >/dev/null - rm -rf $TEMP_DIR + rm -rf "$TEMP_DIR" } TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null -if ! pveversion | grep -Eq "pve-manager/8\.[1-3](\.[0-9]+)*"; then +pushd "$TEMP_DIR" >/dev/null +if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then msg_error "This version of Proxmox Virtual Environment is not supported" echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." echo -e "Exiting..." @@ -121,7 +121,7 @@ function default_settings() { } function advanced_settings() { METHOD="advanced" - VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" 3>&1 1>&2 2>&3) + VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 "$NEXTID" --title "VIRTUAL MACHINE ID" 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Virtual Machine ID: ${BGN}$VMID${CL}" @@ -131,7 +131,7 @@ function advanced_settings() { VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 mikrotik-routeros-chr --title "HOSTNAME" 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then - HN=$(echo ${VM_NAME,,} | tr -d ' ') + HN=$(echo "${VM_NAME,,}" | tr -d ' ') echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" else exit @@ -157,7 +157,7 @@ function advanced_settings() { else exit fi - MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a MAC Address" 8 58 $GEN_MAC --title "MAC ADDRESS" 3>&1 1>&2 2>&3) + MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a MAC Address" 8 58 "$GEN_MAC" --title "MAC ADDRESS" 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then MAC="$MAC1" @@ -168,7 +168,7 @@ function advanced_settings() { VLAN1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" 3>&1 1>&2 2>&3) exitstatus=$? if [ $exitstatus = 0 ]; then - if [ -z $VLAN1 ]; then + if [ -z "$VLAN1" ]; then VLAN1="Default" VLAN="" echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" else @@ -179,7 +179,7 @@ function advanced_settings() { 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 = 0 ]; then - if [ -z $MTU1 ]; then + if [ -z "$MTU1" ]; then MTU1="Default" MTU="" echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" else @@ -221,9 +221,9 @@ start_script post_to_api_vm msg_info "Validating Storage" 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)}') + 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 @@ -259,8 +259,8 @@ echo -en "\e[1A\e[0K" FILE=$(basename $URL) msg_ok "Downloaded ${CL}${BL}$FILE${CL}" msg_info "Extracting Mikrotik RouterOS CHR Disk Image" -gunzip -f -S .zip $FILE -STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') +gunzip -f -S .zip "$FILE" +STORAGE_TYPE=$(pvesm status -storage "$STORAGE" | awk 'NR>1 {print $2}') case $STORAGE_TYPE in nfs | dir) DISK_EXT=".qcow2" @@ -284,11 +284,11 @@ DISK_REF="${STORAGE}:${DISK_REF:-}${DISK_VAR:-}" msg_ok "Extracted Mikrotik RouterOS CHR Disk Image" msg_info "Creating Mikrotik RouterOS CHR VM" -qm create $VMID -tablet 0 -localtime 1 -cores $CORE_COUNT -memory $RAM_SIZE -name $HN \ - -tags community-script -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU \ +qm create "$VMID" -tablet 0 -localtime 1 -cores "$CORE_COUNT" -memory "$RAM_SIZE" -name "$HN" \ + -tags community-script -net0 virtio,bridge="$BRG",macaddr="$MAC"$VLAN"$MTU" \ -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -qm importdisk $VMID ${FILE%.*} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null -qm set $VMID \ +qm importdisk "$VMID" "${FILE%.*}" "$STORAGE" "${DISK_IMPORT:-}" 1>&/dev/null +qm set "$VMID" \ -scsi0 "$DISK_REF" \ -boot order=scsi0 \ -description "
@@ -300,7 +300,7 @@ qm set $VMID \ msg_ok "Mikrotik RouterOS CHR VM ${CL}${BL}(${HN})" if [ "$START_VM" == "yes" ]; then msg_info "Starting Mikrotik RouterOS CHR VM" - qm start $VMID + qm start "$VMID" msg_ok "Started Mikrotik RouterOS CHR VM" fi post_update_to_api "done" "none" diff --git a/vm/nextcloud-vm.sh b/vm/nextcloud-vm.sh index 5d62fc097..a33bc6a38 100644 --- a/vm/nextcloud-vm.sh +++ b/vm/nextcloud-vm.sh @@ -59,19 +59,19 @@ function error_handler() { } function cleanup_vmid() { - if qm status $VMID &>/dev/null; then - qm stop $VMID &>/dev/null - qm destroy $VMID &>/dev/null + if qm status "$VMID" &>/dev/null; then + qm stop "$VMID" &>/dev/null + qm destroy "$VMID" &>/dev/null fi } function cleanup() { popd >/dev/null - rm -rf $TEMP_DIR + rm -rf "$TEMP_DIR" } TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null +pushd "$TEMP_DIR" >/dev/null if whiptail --backtitle "Proxmox VE Helper Scripts" --title "$NAME" --yesno "This will create a New $NAME. Proceed?" 10 58; then : else @@ -104,7 +104,7 @@ function check_root() { } function pve_check() { - if ! pveversion | grep -Eq "pve-manager/8\.[1-3](\.[0-9]+)*"; then + if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then msg_error "This version of Proxmox Virtual Environment is not supported" echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." echo -e "Exiting..." @@ -174,7 +174,7 @@ function default_settings() { function advanced_settings() { METHOD="advanced" while true; do - if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 "$NEXTID" --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then if [ -z "$VMID" ]; then VMID="$NEXTID" fi @@ -194,7 +194,7 @@ function advanced_settings() { "i440fx" "Machine i440fx" ON \ "q35" "Machine q35" OFF \ 3>&1 1>&2 2>&3); then - if [ $MACH = q35 ]; then + if [ "$MACH" = q35 ]; then echo -e "${DGN}Using Machine Type: ${BGN}$MACH${CL}" FORMAT="" MACHINE=" -machine q35" @@ -211,7 +211,7 @@ function advanced_settings() { "0" "None (Default)" ON \ "1" "Write Through" OFF \ 3>&1 1>&2 2>&3); then - if [ $DISK_CACHE = "1" ]; then + if [ "$DISK_CACHE" = "1" ]; then echo -e "${DGN}Using Disk Cache: ${BGN}Write Through${CL}" DISK_CACHE="cache=writethrough," else @@ -223,11 +223,11 @@ function advanced_settings() { fi if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 turnkey-nextcloud-vm --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $VM_NAME ]; then + if [ -z "$VM_NAME" ]; then HN="$HN" echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" else - HN=$(echo ${VM_NAME,,} | tr -d ' ') + HN=$(echo "${VM_NAME,,}" | tr -d ' ') echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" fi else @@ -238,7 +238,7 @@ function advanced_settings() { "0" "KVM64 (Default)" ON \ "1" "Host" OFF \ 3>&1 1>&2 2>&3); then - if [ $CPU_TYPE1 = "1" ]; then + if [ "$CPU_TYPE1" = "1" ]; then echo -e "${DGN}Using CPU Model: ${BGN}Host${CL}" CPU_TYPE=" -cpu host" else @@ -250,7 +250,7 @@ function advanced_settings() { fi if 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); then - if [ -z $CORE_COUNT ]; then + if [ -z "$CORE_COUNT" ]; then CORE_COUNT="2" echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" else @@ -261,7 +261,7 @@ function advanced_settings() { fi if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 2048 --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $RAM_SIZE ]; then + if [ -z "$RAM_SIZE" ]; then RAM_SIZE="2048" echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" else @@ -272,7 +272,7 @@ function advanced_settings() { fi if 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); then - if [ -z $BRG ]; then + if [ -z "$BRG" ]; then BRG="vmbr0" echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" else @@ -282,8 +282,8 @@ function advanced_settings() { exit-script fi - if 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); then - if [ -z $MAC1 ]; then + if 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); then + if [ -z "$MAC1" ]; then MAC="$GEN_MAC" echo -e "${DGN}Using MAC Address: ${BGN}$MAC${CL}" else @@ -295,7 +295,7 @@ function advanced_settings() { fi if 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); then - if [ -z $VLAN1 ]; then + if [ -z "$VLAN1" ]; then VLAN1="Default" VLAN="" echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" @@ -308,7 +308,7 @@ function advanced_settings() { fi if 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); then - if [ -z $MTU1 ]; then + if [ -z "$MTU1" ]; then MTU1="Default" MTU="" echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" @@ -359,9 +359,9 @@ post_to_api_vm msg_info "Validating Storage" 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)}') + 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 @@ -394,7 +394,7 @@ echo -en "\e[1A\e[0K" FILE=$(basename $URL) msg_ok "Downloaded ${CL}${BL}${FILE}${CL}" -STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') +STORAGE_TYPE=$(pvesm status -storage "$STORAGE" | awk 'NR>1 {print $2}') case $STORAGE_TYPE in nfs | dir) DISK_EXT=".raw" @@ -412,20 +412,20 @@ btrfs) esac for i in {0,1,2}; do disk="DISK$i" - eval DISK${i}=vm-${VMID}-disk-${i}${DISK_EXT:-} - eval DISK${i}_REF=${STORAGE}:${DISK_REF:-}${!disk} + eval DISK"${i}"=vm-"${VMID}"-disk-"${i}"${DISK_EXT:-} + eval DISK"${i}"_REF="${STORAGE}":"${DISK_REF:-}"${!disk} done msg_info "Creating a $NAME" -qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios seabios${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \ - -name $HN -tags community-script -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null -pvesm alloc $STORAGE $VMID $DISK1 12G 1>&/dev/null -qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null -qm set $VMID \ - -efidisk0 ${DISK0_REF}${FORMAT} \ - -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN} \ - -scsi1 ${DISK2_REF},${DISK_CACHE}${THIN} \ +qm create "$VMID" -agent 1"${MACHINE}" -tablet 0 -localtime 1 -bios seabios"${CPU_TYPE}" -cores "$CORE_COUNT" -memory "$RAM_SIZE" \ + -name "$HN" -tags community-script -net0 virtio,bridge="$BRG",macaddr="$MAC"$VLAN"$MTU" -onboot 1 -ostype l26 -scsihw virtio-scsi-pci +pvesm alloc "$STORAGE" "$VMID" "$DISK0" 4M 1>&/dev/null +pvesm alloc "$STORAGE" "$VMID" "$DISK1" 12G 1>&/dev/null +qm importdisk "$VMID" "${FILE}" "$STORAGE" "${DISK_IMPORT:-}" 1>&/dev/null +qm set "$VMID" \ + -efidisk0 "${DISK0_REF}"${FORMAT} \ + -scsi0 "${DISK1_REF}",${DISK_CACHE}${THIN} \ + -scsi1 "${DISK2_REF}",${DISK_CACHE}${THIN} \ -boot order='scsi1;scsi0' \ -description "
@@ -436,7 +436,7 @@ qm set $VMID \ msg_ok "Created a $NAME ${CL}${BL}(${HN})" if [ "$START_VM" == "yes" ]; then msg_info "Starting $NAME" - qm start $VMID + qm start "$VMID" msg_ok "Started $NAME" fi post_update_to_api "done" "none" diff --git a/vm/openwrt.sh b/vm/openwrt.sh index f5dfb50fa..4a3819d1f 100644 --- a/vm/openwrt.sh +++ b/vm/openwrt.sh @@ -62,19 +62,19 @@ function error_handler() { } function cleanup_vmid() { - if qm status $VMID &>/dev/null; then - qm stop $VMID &>/dev/null - qm destroy $VMID &>/dev/null + if qm status "$VMID" &>/dev/null; then + qm stop "$VMID" &>/dev/null + qm destroy "$VMID" &>/dev/null fi } function cleanup() { popd >/dev/null - rm -rf $TEMP_DIR + rm -rf "$TEMP_DIR" } TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null +pushd "$TEMP_DIR" >/dev/null function send_line_to_vm() { echo -e "${DGN}Sending line: ${YW}$1${CL}" for ((i = 0; i < ${#1}; i++)); do @@ -140,13 +140,13 @@ function send_line_to_vm() { "(") character="shift-9" ;; ")") character="shift-0" ;; esac - qm sendkey $VMID "$character" + qm sendkey "$VMID" "$character" done - qm sendkey $VMID ret + qm sendkey "$VMID" ret } TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null +pushd "$TEMP_DIR" >/dev/null if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "OpenWrt VM" --yesno "This will create a New OpenWrt VM. Proceed?" 10 58); then : @@ -170,7 +170,7 @@ function msg_error() { } function pve_check() { - if ! pveversion | grep -Eq "pve-manager/8\.[1-3](\.[0-9]+)*"; then + if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then msg_error "This version of Proxmox Virtual Environment is not supported" echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." echo -e "Exiting..." @@ -243,7 +243,7 @@ function default_settings() { function advanced_settings() { METHOD="advanced" while true; do - if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 "$NEXTID" --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then if [ -z "$VMID" ]; then VMID="$NEXTID" fi @@ -260,10 +260,10 @@ function advanced_settings() { done if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 openwrt --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $VM_NAME ]; then + if [ -z "$VM_NAME" ]; then HN="openwrt" else - HN=$(echo ${VM_NAME,,} | tr -d ' ') + HN=$(echo "${VM_NAME,,}" | tr -d ' ') fi echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" else @@ -271,7 +271,7 @@ function advanced_settings() { fi if CORE_COUNT=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate CPU Cores" 8 58 1 --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $CORE_COUNT ]; then + if [ -z "$CORE_COUNT" ]; then CORE_COUNT="1" fi echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" @@ -280,7 +280,7 @@ function advanced_settings() { fi if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 256 --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $RAM_SIZE ]; then + if [ -z "$RAM_SIZE" ]; then RAM_SIZE="256" fi echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" @@ -289,7 +289,7 @@ function advanced_settings() { fi if BRG=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a WAN Bridge" 8 58 vmbr0 --title "WAN BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $BRG ]; then + if [ -z "$BRG" ]; then BRG="vmbr0" fi echo -e "${DGN}Using WAN Bridge: ${BGN}$BRG${CL}" @@ -298,7 +298,7 @@ function advanced_settings() { fi if LAN_BRG=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a LAN Bridge" 8 58 vmbr0 --title "LAN BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $LAN_BRG ]; then + if [ -z "$LAN_BRG" ]; then LAN_BRG="vmbr0" fi echo -e "${DGN}Using LAN Bridge: ${BGN}$LAN_BRG${CL}" @@ -306,8 +306,8 @@ function advanced_settings() { exit-script fi - if LAN_IP_ADDR=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a router IP" 8 58 $LAN_IP_ADDR --title "LAN IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $LAN_IP_ADDR ]; then + if LAN_IP_ADDR=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a router IP" 8 58 "$LAN_IP_ADDR" --title "LAN IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if [ -z "$LAN_IP_ADDR" ]; then LAN_IP_ADDR="192.168.1.1" fi echo -e "${DGN}Using LAN IP ADDRESS: ${BGN}$LAN_IP_ADDR${CL}" @@ -315,8 +315,8 @@ function advanced_settings() { exit-script fi - if LAN_NETMASK=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a router netmask" 8 58 $LAN_NETMASK --title "LAN NETMASK" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $LAN_NETMASK ]; then + if LAN_NETMASK=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a router netmask" 8 58 "$LAN_NETMASK" --title "LAN NETMASK" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if [ -z "$LAN_NETMASK" ]; then LAN_NETMASK="255.255.255.0" fi echo -e "${DGN}Using LAN NETMASK: ${BGN}$LAN_NETMASK${CL}" @@ -324,8 +324,8 @@ function advanced_settings() { exit-script fi - if MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a WAN MAC Address" 8 58 $GEN_MAC --title "WAN MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $MAC1 ]; then + if MAC1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a WAN MAC Address" 8 58 "$GEN_MAC" --title "WAN MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if [ -z "$MAC1" ]; then MAC="$GEN_MAC" else MAC="$MAC1" @@ -335,8 +335,8 @@ function advanced_settings() { exit-script fi - if MAC2=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a LAN MAC Address" 8 58 $GEN_MAC_LAN --title "LAN MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $MAC2 ]; then + if MAC2=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a LAN MAC Address" 8 58 "$GEN_MAC_LAN" --title "LAN MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if [ -z "$MAC2" ]; then LAN_MAC="$GEN_MAC_LAN" else LAN_MAC="$MAC2" @@ -347,7 +347,7 @@ function advanced_settings() { fi if VLAN1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a WAN Vlan (leave blank for default)" 8 58 --title "WAN VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $VLAN1 ]; then + if [ -z "$VLAN1" ]; then VLAN1="Default" VLAN="" else @@ -359,7 +359,7 @@ function advanced_settings() { fi if VLAN2=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set a LAN Vlan" 8 58 999 --title "LAN VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $VLAN2 ]; then + if [ -z "$VLAN2" ]; then VLAN2="999" LAN_VLAN=",tag=$VLAN2" else @@ -371,7 +371,7 @@ function advanced_settings() { fi if 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); then - if [ -z $MTU1 ]; then + if [ -z "$MTU1" ]; then MTU1="Default" MTU="" else @@ -418,9 +418,9 @@ post_to_api_vm msg_info "Validating Storage" 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)}') + 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 @@ -455,15 +455,15 @@ sleep 2 msg_ok "${CL}${BL}${URL}${CL}" curl -f#SL -o "$(basename "$URL")" "$URL" echo -en "\e[1A\e[0K" -FILE=$(basename $URL) +FILE=$(basename "$URL") msg_ok "Downloaded ${CL}${BL}$FILE${CL}" -gunzip -f $FILE >/dev/null 2>/dev/null || true +gunzip -f "$FILE" >/dev/null 2>/dev/null || true NEWFILE="${FILE%.*}" FILE="$NEWFILE" -mv $FILE ${FILE%.*} -qemu-img resize -f raw ${FILE%.*} 512M >/dev/null 2>/dev/null +mv "$FILE" "${FILE%.*}" +qemu-img resize -f raw "${FILE%.*}" 512M >/dev/null 2>/dev/null msg_ok "Extracted & Resized OpenWrt Disk Image ${CL}${BL}$FILE${CL}" -STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') +STORAGE_TYPE=$(pvesm status -storage "$STORAGE" | awk 'NR>1 {print $2}') case $STORAGE_TYPE in nfs | dir) DISK_EXT=".qcow2" @@ -478,18 +478,18 @@ btrfs) 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} + eval DISK"${i}"=vm-"${VMID}"-disk-"${i}"${DISK_EXT:-} + eval DISK"${i}"_REF="${STORAGE}":"${DISK_REF:-}"${!disk} done msg_info "Creating OpenWrt VM" -qm create $VMID -cores $CORE_COUNT -memory $RAM_SIZE -name $HN \ +qm create "$VMID" -cores "$CORE_COUNT" -memory "$RAM_SIZE" -name "$HN" \ -onboot 1 -ostype l26 -scsihw virtio-scsi-pci --tablet 0 -pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null -qm importdisk $VMID ${FILE%.*} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null -qm set $VMID \ - -efidisk0 ${DISK0_REF},efitype=4m,size=4M \ - -scsi0 ${DISK1_REF},size=512M \ +pvesm alloc "$STORAGE" "$VMID" "$DISK0" 4M 1>&/dev/null +qm importdisk "$VMID" "${FILE%.*}" "$STORAGE" "${DISK_IMPORT:-}" 1>&/dev/null +qm set "$VMID" \ + -efidisk0 "${DISK0_REF}",efitype=4m,size=4M \ + -scsi0 "${DISK1_REF}",size=512M \ -boot order=scsi0 \ -tags community-script \ -description "
@@ -500,7 +500,7 @@ qm set $VMID \
" >/dev/null msg_ok "Created OpenWrt VM ${CL}${BL}(${HN})" msg_info "OpenWrt is being started in order to configure the network interfaces." -qm start $VMID +qm start "$VMID" sleep 15 msg_ok "Network interfaces are being configured as OpenWrt initiates." send_line_to_vm "" @@ -517,17 +517,17 @@ send_line_to_vm "uci set network.lan.netmask=${LAN_NETMASK}" send_line_to_vm "uci commit" send_line_to_vm "halt" msg_ok "Network interfaces have been successfully configured." -until qm status $VMID | grep -q "stopped"; do +until qm status "$VMID" | grep -q "stopped"; do sleep 2 done msg_info "Bridge interfaces are being added." -qm set $VMID \ - -net0 virtio,bridge=${LAN_BRG},macaddr=${LAN_MAC}${LAN_VLAN}${MTU} \ - -net1 virtio,bridge=${BRG},macaddr=${MAC}${VLAN}${MTU} >/dev/null 2>/dev/null +qm set "$VMID" \ + -net0 virtio,bridge="${LAN_BRG}",macaddr="${LAN_MAC}"${LAN_VLAN}"${MTU}" \ + -net1 virtio,bridge="${BRG}",macaddr="${MAC}"${VLAN}"${MTU}" >/dev/null 2>/dev/null msg_ok "Bridge interfaces have been successfully added." if [ "$START_VM" == "yes" ]; then msg_info "Starting OpenWrt VM" - qm start $VMID + qm start "$VMID" msg_ok "Started OpenWrt VM" fi VLAN_FINISH="" diff --git a/vm/opnsense-vm.sh b/vm/opnsense-vm.sh index 93b89c1e5..ae62dca56 100644 --- a/vm/opnsense-vm.sh +++ b/vm/opnsense-vm.sh @@ -164,7 +164,7 @@ function msg_error() { } function pve_check() { - if ! pveversion | grep -Eq "pve-manager/8.[1-3]"; then + if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then msg_error "This version of Proxmox Virtual Environment is not supported" echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." echo -e "Exiting..." diff --git a/vm/ubuntu2204-vm.sh b/vm/ubuntu2204-vm.sh index 4de7c6606..57bba2b17 100644 --- a/vm/ubuntu2204-vm.sh +++ b/vm/ubuntu2204-vm.sh @@ -76,19 +76,19 @@ function error_handler() { } function cleanup_vmid() { - if qm status $VMID &>/dev/null; then - qm stop $VMID &>/dev/null - qm destroy $VMID &>/dev/null + if qm status "$VMID" &>/dev/null; then + qm stop "$VMID" &>/dev/null + qm destroy "$VMID" &>/dev/null fi } function cleanup() { popd >/dev/null - rm -rf $TEMP_DIR + rm -rf "$TEMP_DIR" } TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null +pushd "$TEMP_DIR" >/dev/null if whiptail --backtitle "Proxmox VE Helper Scripts" --title "Ubuntu 22.04 VM" --yesno "This will create a New Ubuntu 22.04 VM. Proceed?" 10 58; then : else @@ -121,7 +121,7 @@ function check_root() { } function pve_check() { - if ! pveversion | grep -Eq "pve-manager/8\.[1-3](\.[0-9]+)*"; then + if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then msg_error "${CROSS}${RD}This version of Proxmox Virtual Environment is not supported" echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." echo -e "Exiting..." @@ -194,7 +194,7 @@ function default_settings() { function advanced_settings() { METHOD="advanced" while true; do - if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 "$NEXTID" --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then if [ -z "$VMID" ]; then VMID="$NEXTID" fi @@ -214,7 +214,7 @@ function advanced_settings() { "i440fx" "Machine i440fx" ON \ "q35" "Machine q35" OFF \ 3>&1 1>&2 2>&3); then - if [ $MACH = q35 ]; then + if [ "$MACH" = q35 ]; then echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}$MACH${CL}" FORMAT="" MACHINE=" -machine q35" @@ -246,7 +246,7 @@ function advanced_settings() { "0" "None (Default)" ON \ "1" "Write Through" OFF \ 3>&1 1>&2 2>&3); then - if [ $DISK_CACHE = "1" ]; then + if [ "$DISK_CACHE" = "1" ]; then echo -e "${DISKSIZE}${BOLD}${DGN}Disk Cache: ${BGN}Write Through${CL}" DISK_CACHE="cache=writethrough," else @@ -258,11 +258,11 @@ function advanced_settings() { fi if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 ubuntu --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $VM_NAME ]; then + if [ -z "$VM_NAME" ]; then HN="ubuntu" echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}$HN${CL}" else - HN=$(echo ${VM_NAME,,} | tr -d ' ') + HN=$(echo "${VM_NAME,,}" | tr -d ' ') echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}$HN${CL}" fi else @@ -273,7 +273,7 @@ function advanced_settings() { "0" "KVM64 (Default)" ON \ "1" "Host" OFF \ 3>&1 1>&2 2>&3); then - if [ $CPU_TYPE1 = "1" ]; then + if [ "$CPU_TYPE1" = "1" ]; then echo -e "${OS}${BOLD}${DGN}CPU Model: ${BGN}Host${CL}" CPU_TYPE=" -cpu host" else @@ -285,7 +285,7 @@ function advanced_settings() { fi if 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); then - if [ -z $CORE_COUNT ]; then + if [ -z "$CORE_COUNT" ]; then CORE_COUNT="2" echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}$CORE_COUNT${CL}" else @@ -296,7 +296,7 @@ function advanced_settings() { fi if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 2048 --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $RAM_SIZE ]; then + if [ -z "$RAM_SIZE" ]; then RAM_SIZE="2048" echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}$RAM_SIZE${CL}" else @@ -307,7 +307,7 @@ function advanced_settings() { fi if 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); then - if [ -z $BRG ]; then + if [ -z "$BRG" ]; then BRG="vmbr0" echo -e "${BRIDGE}${BOLD}${DGN}Bridge: ${BGN}$BRG${CL}" else @@ -317,8 +317,8 @@ function advanced_settings() { exit-script fi - if 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); then - if [ -z $MAC1 ]; then + if 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); then + if [ -z "$MAC1" ]; then MAC="$GEN_MAC" echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}$MAC${CL}" else @@ -330,7 +330,7 @@ function advanced_settings() { fi if 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); then - if [ -z $VLAN1 ]; then + if [ -z "$VLAN1" ]; then VLAN1="Default" VLAN="" echo -e "${VLANTAG}${BOLD}${DGN}VLAN: ${BGN}$VLAN1${CL}" @@ -343,7 +343,7 @@ function advanced_settings() { fi if 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); then - if [ -z $MTU1 ]; then + if [ -z "$MTU1" ]; then MTU1="Default" MTU="" echo -e "${DEFAULT}${BOLD}${DGN}Interface MTU Size: ${BGN}$MTU1${CL}" @@ -393,9 +393,9 @@ post_to_api_vm msg_info "Validating Storage" 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)}') + 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 @@ -428,7 +428,7 @@ echo -en "\e[1A\e[0K" FILE=$(basename $URL) msg_ok "Downloaded ${CL}${BL}${FILE}${CL}" -STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') +STORAGE_TYPE=$(pvesm status -storage "$STORAGE" | awk 'NR>1 {print $2}') case $STORAGE_TYPE in nfs | dir | cifs) DISK_EXT=".qcow2" @@ -446,19 +446,19 @@ btrfs) 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} + eval DISK"${i}"=vm-"${VMID}"-disk-"${i}""${DISK_EXT:-}" + eval DISK"${i}"_REF="${STORAGE}":"${DISK_REF:-}""${!disk}" done msg_info "Creating a Ubuntu 22.04 VM" -qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios ovmf${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \ - -name $HN -tags community-script -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null -qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null -qm set $VMID \ - -efidisk0 ${DISK0_REF}${FORMAT} \ - -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=${DISK_SIZE} \ - -ide2 ${STORAGE}:cloudinit \ +qm create "$VMID" -agent 1"${MACHINE}" -tablet 0 -localtime 1 -bios ovmf"${CPU_TYPE}" -cores "$CORE_COUNT" -memory "$RAM_SIZE" \ + -name "$HN" -tags community-script -net0 virtio,bridge="$BRG",macaddr="$MAC""$VLAN""$MTU" -onboot 1 -ostype l26 -scsihw virtio-scsi-pci +pvesm alloc "$STORAGE" "$VMID" "$DISK0" 4M 1>&/dev/null +qm importdisk "$VMID" "${FILE}" "$STORAGE" "${DISK_IMPORT:-}" 1>&/dev/null +qm set "$VMID" \ + -efidisk0 "${DISK0_REF}"${FORMAT} \ + -scsi0 "${DISK1_REF}",${DISK_CACHE}${THIN}size="${DISK_SIZE}" \ + -ide2 "${STORAGE}":cloudinit \ -boot order=scsi0 \ -serial0 socket >/dev/null DESCRIPTION=$( @@ -494,16 +494,16 @@ EOF qm set "$VMID" -description "$DESCRIPTION" >/dev/null if [ -n "$DISK_SIZE" ]; then msg_info "Resizing disk to $DISK_SIZE GB" - qm resize $VMID scsi0 ${DISK_SIZE} >/dev/null + 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 + qm resize "$VMID" scsi0 "${DEFAULT_DISK_SIZE}" >/dev/null fi msg_ok "Created a Ubuntu 22.04 VM ${CL}${BL}(${HN})" if [ "$START_VM" == "yes" ]; then msg_info "Starting Ubuntu 22.04 VM" - qm start $VMID + qm start "$VMID" msg_ok "Started Ubuntu 22.04 VM" fi post_update_to_api "done" "none" diff --git a/vm/ubuntu2410-vm.sh b/vm/ubuntu2410-vm.sh index b2b03b1f1..ef5a3a6eb 100644 --- a/vm/ubuntu2410-vm.sh +++ b/vm/ubuntu2410-vm.sh @@ -76,19 +76,19 @@ function error_handler() { } function cleanup_vmid() { - if qm status $VMID &>/dev/null; then - qm stop $VMID &>/dev/null - qm destroy $VMID &>/dev/null + if qm status "$VMID" &>/dev/null; then + qm stop "$VMID" &>/dev/null + qm destroy "$VMID" &>/dev/null fi } function cleanup() { popd >/dev/null - rm -rf $TEMP_DIR + rm -rf "$TEMP_DIR" } TEMP_DIR=$(mktemp -d) -pushd $TEMP_DIR >/dev/null +pushd "$TEMP_DIR" >/dev/null if whiptail --backtitle "Proxmox VE Helper Scripts" --title "Ubuntu 24.10 VM" --yesno "This will create a New Ubuntu 24.10 VM. Proceed?" 10 58; then : else @@ -121,7 +121,7 @@ function check_root() { } function pve_check() { - if ! pveversion | grep -Eq "pve-manager/8\.[1-3](\.[0-9]+)*"; then + if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[0-9]+)*"; then msg_error "${CROSS}${RD}This version of Proxmox Virtual Environment is not supported" echo -e "Requires Proxmox Virtual Environment Version 8.1 or later." echo -e "Exiting..." @@ -194,7 +194,7 @@ function default_settings() { function advanced_settings() { METHOD="advanced" while true; do - if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 $NEXTID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then + if VMID=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Virtual Machine ID" 8 58 "$NEXTID" --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then if [ -z "$VMID" ]; then VMID="$NEXTID" fi @@ -214,7 +214,7 @@ function advanced_settings() { "i440fx" "Machine i440fx" ON \ "q35" "Machine q35" OFF \ 3>&1 1>&2 2>&3); then - if [ $MACH = q35 ]; then + if [ "$MACH" = q35 ]; then echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}$MACH${CL}" FORMAT="" MACHINE=" -machine q35" @@ -246,7 +246,7 @@ function advanced_settings() { "0" "None (Default)" ON \ "1" "Write Through" OFF \ 3>&1 1>&2 2>&3); then - if [ $DISK_CACHE = "1" ]; then + if [ "$DISK_CACHE" = "1" ]; then echo -e "${DISKSIZE}${BOLD}${DGN}Disk Cache: ${BGN}Write Through${CL}" DISK_CACHE="cache=writethrough," else @@ -258,11 +258,11 @@ function advanced_settings() { fi if VM_NAME=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Set Hostname" 8 58 ubuntu --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $VM_NAME ]; then + if [ -z "$VM_NAME" ]; then HN="ubuntu" echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}$HN${CL}" else - HN=$(echo ${VM_NAME,,} | tr -d ' ') + HN=$(echo "${VM_NAME,,}" | tr -d ' ') echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}$HN${CL}" fi else @@ -273,7 +273,7 @@ function advanced_settings() { "0" "KVM64 (Default)" ON \ "1" "Host" OFF \ 3>&1 1>&2 2>&3); then - if [ $CPU_TYPE1 = "1" ]; then + if [ "$CPU_TYPE1" = "1" ]; then echo -e "${OS}${BOLD}${DGN}CPU Model: ${BGN}Host${CL}" CPU_TYPE=" -cpu host" else @@ -285,7 +285,7 @@ function advanced_settings() { fi if 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); then - if [ -z $CORE_COUNT ]; then + if [ -z "$CORE_COUNT" ]; then CORE_COUNT="2" echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}$CORE_COUNT${CL}" else @@ -296,7 +296,7 @@ function advanced_settings() { fi if RAM_SIZE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --inputbox "Allocate RAM in MiB" 8 58 2048 --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then - if [ -z $RAM_SIZE ]; then + if [ -z "$RAM_SIZE" ]; then RAM_SIZE="2048" echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}$RAM_SIZE${CL}" else @@ -307,7 +307,7 @@ function advanced_settings() { fi if 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); then - if [ -z $BRG ]; then + if [ -z "$BRG" ]; then BRG="vmbr0" echo -e "${BRIDGE}${BOLD}${DGN}Bridge: ${BGN}$BRG${CL}" else @@ -317,8 +317,8 @@ function advanced_settings() { exit-script fi - if 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); then - if [ -z $MAC1 ]; then + if 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); then + if [ -z "$MAC1" ]; then MAC="$GEN_MAC" echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}$MAC${CL}" else @@ -330,7 +330,7 @@ function advanced_settings() { fi if 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); then - if [ -z $VLAN1 ]; then + if [ -z "$VLAN1" ]; then VLAN1="Default" VLAN="" echo -e "${VLANTAG}${BOLD}${DGN}VLAN: ${BGN}$VLAN1${CL}" @@ -343,7 +343,7 @@ function advanced_settings() { fi if 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); then - if [ -z $MTU1 ]; then + if [ -z "$MTU1" ]; then MTU1="Default" MTU="" echo -e "${DEFAULT}${BOLD}${DGN}Interface MTU Size: ${BGN}$MTU1${CL}" @@ -393,9 +393,9 @@ post_to_api_vm msg_info "Validating Storage" 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)}') + 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 @@ -428,7 +428,7 @@ echo -en "\e[1A\e[0K" FILE=$(basename $URL) msg_ok "Downloaded ${CL}${BL}${FILE}${CL}" -STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') +STORAGE_TYPE=$(pvesm status -storage "$STORAGE" | awk 'NR>1 {print $2}') case $STORAGE_TYPE in nfs | dir | cifs) DISK_EXT=".qcow2" @@ -446,19 +446,19 @@ btrfs) 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} + eval DISK"${i}"=vm-"${VMID}"-disk-"${i}"${DISK_EXT:-} + eval DISK"${i}"_REF="${STORAGE}":"${DISK_REF:-}"${!disk} done msg_info "Creating a Ubuntu 24.10 VM" -qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios ovmf${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \ - -name $HN -tags community-script -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null -qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null -qm set $VMID \ - -efidisk0 ${DISK0_REF}${FORMAT} \ - -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=${DISK_SIZE} \ - -ide2 ${STORAGE}:cloudinit \ +qm create "$VMID" -agent 1"${MACHINE}" -tablet 0 -localtime 1 -bios ovmf"${CPU_TYPE}" -cores "$CORE_COUNT" -memory "$RAM_SIZE" \ + -name "$HN" -tags community-script -net0 virtio,bridge="$BRG",macaddr="$MAC"$VLAN"$MTU" -onboot 1 -ostype l26 -scsihw virtio-scsi-pci +pvesm alloc "$STORAGE" "$VMID" "$DISK0" 4M 1>&/dev/null +qm importdisk "$VMID" "${FILE}" "$STORAGE" "${DISK_IMPORT:-}" 1>&/dev/null +qm set "$VMID" \ + -efidisk0 "${DISK0_REF}"${FORMAT} \ + -scsi0 "${DISK1_REF}",${DISK_CACHE}${THIN}size="${DISK_SIZE}" \ + -ide2 "${STORAGE}":cloudinit \ -boot order=scsi0 \ -serial0 socket >/dev/null DESCRIPTION=$( @@ -494,16 +494,16 @@ EOF qm set "$VMID" -description "$DESCRIPTION" >/dev/null if [ -n "$DISK_SIZE" ]; then msg_info "Resizing disk to $DISK_SIZE GB" - qm resize $VMID scsi0 ${DISK_SIZE} >/dev/null + 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 + qm resize "$VMID" scsi0 "${DEFAULT_DISK_SIZE}" >/dev/null fi msg_ok "Created a Ubuntu 24.10 VM ${CL}${BL}(${HN})" if [ "$START_VM" == "yes" ]; then msg_info "Starting Ubuntu 24.10 VM" - qm start $VMID + qm start "$VMID" msg_ok "Started Ubuntu 24.10 VM" fi post_update_to_api "done" "none"