From 24551de29206f1a1b71a1df413125126353d0757 Mon Sep 17 00:00:00 2001 From: tteckster Date: Thu, 28 Sep 2023 06:40:15 -0400 Subject: [PATCH 1/2] Update haos-vm.sh - Add a function to verify if the user is the root user (without using sudo). - Set default disk cache to writethrough - Set default CPU type to host --- vm/haos-vm.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/vm/haos-vm.sh b/vm/haos-vm.sh index 8294ec68..05dd891e 100644 --- a/vm/haos-vm.sh +++ b/vm/haos-vm.sh @@ -84,9 +84,19 @@ function msg_error() { 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 +} + function pve_check() { if ! pveversion | grep -Eq "pve-manager/(7\.[2-9]|8\.[0-9])"; then - echo -e "${CROSS} This version of Proxmox Virtual Environment is not supported" + msg_error "This version of Proxmox Virtual Environment is not supported" echo -e "Requires PVE Version 7.2 or higher" echo -e "Exiting..." sleep 2 @@ -96,7 +106,7 @@ function pve_check() { function arch_check() { if [ "$(dpkg --print-architecture)" != "amd64" ]; then - echo -e "\n ${CROSS} This script will not work with PiMox! \n" + msg_error "This script will not work with PiMox! \n" echo -e "Exiting..." sleep 2 exit @@ -127,9 +137,9 @@ function default_settings() { VMID="$NEXTID" FORMAT=",efitype=4m" MACHINE="" - DISK_CACHE="" + DISK_CACHE="cache=writethrough," HN="haos$stable" - CPU_TYPE="" + CPU_TYPE=" -cpu host" CORE_COUNT="2" RAM_SIZE="4096" BRG="vmbr0" @@ -140,9 +150,9 @@ function default_settings() { echo -e "${DGN}Using HAOS Version: ${BGN}${BRANCH}${CL}" echo -e "${DGN}Using Virtual Machine ID: ${BGN}${VMID}${CL}" echo -e "${DGN}Using Machine Type: ${BGN}i440fx${CL}" - echo -e "${DGN}Using Disk Cache: ${BGN}Default${CL}" + echo -e "${DGN}Using Disk Cache: ${BGN}Writethrough${CL}" echo -e "${DGN}Using Hostname: ${BGN}${HN}${CL}" - echo -e "${DGN}Using CPU Model: ${BGN}Default${CL}" + echo -e "${DGN}Using CPU Model: ${BGN}Host${CL}" echo -e "${DGN}Allocated Cores: ${BGN}${CORE_COUNT}${CL}" echo -e "${DGN}Allocated RAM: ${BGN}${RAM_SIZE}${CL}" echo -e "${DGN}Using Bridge: ${BGN}${BRG}${CL}" @@ -340,6 +350,7 @@ function start_script() { fi } +check_root arch_check pve_check ssh_check From 9d7372b679bfb77406478d1eac80e35cc8821a11 Mon Sep 17 00:00:00 2001 From: tteckster Date: Thu, 28 Sep 2023 06:52:05 -0400 Subject: [PATCH 2/2] Update haos-vm.sh - Set "Advanced" defaults --- vm/haos-vm.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vm/haos-vm.sh b/vm/haos-vm.sh index 05dd891e..27dcb8ce 100644 --- a/vm/haos-vm.sh +++ b/vm/haos-vm.sh @@ -150,7 +150,7 @@ function default_settings() { echo -e "${DGN}Using HAOS Version: ${BGN}${BRANCH}${CL}" echo -e "${DGN}Using Virtual Machine ID: ${BGN}${VMID}${CL}" echo -e "${DGN}Using Machine Type: ${BGN}i440fx${CL}" - echo -e "${DGN}Using Disk Cache: ${BGN}Writethrough${CL}" + echo -e "${DGN}Using Disk Cache: ${BGN}Write Through${CL}" echo -e "${DGN}Using Hostname: ${BGN}${HN}${CL}" echo -e "${DGN}Using CPU Model: ${BGN}Host${CL}" echo -e "${DGN}Allocated Cores: ${BGN}${CORE_COUNT}${CL}" @@ -209,14 +209,14 @@ function advanced_settings() { fi if DISK_CACHE1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISK CACHE" --radiolist "Choose" --cancel-button Exit-Script 10 58 2 \ - "0" "Default" ON \ - "1" "Write Through" OFF \ + "0" "None" OFF \ + "1" "Write Through (Default)" ON \ 3>&1 1>&2 2>&3); then if [ $DISK_CACHE1 = "1" ]; then echo -e "${DGN}Using Disk Cache: ${BGN}Write Through${CL}" DISK_CACHE="cache=writethrough," else - echo -e "${DGN}Using Disk Cache: ${BGN}Default${CL}" + echo -e "${DGN}Using Disk Cache: ${BGN}None${CL}" DISK_CACHE="" fi else @@ -236,14 +236,14 @@ function advanced_settings() { fi if CPU_TYPE1=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "CPU MODEL" --radiolist "Choose" --cancel-button Exit-Script 10 58 2 \ - "0" "KVM64 (Default)" ON \ - "1" "Host" OFF \ + "0" "KVM64" OFF \ + "1" "Host (Default)" ON \ 3>&1 1>&2 2>&3); then if [ $CPU_TYPE1 = "1" ]; then echo -e "${DGN}Using CPU Model: ${BGN}Host${CL}" CPU_TYPE=" -cpu host" else - echo -e "${DGN}Using CPU Model: ${BGN}Default${CL}" + echo -e "${DGN}Using CPU Model: ${BGN}KVM64${CL}" CPU_TYPE="" fi else