1
0
mirror of https://github.com/community-scripts/ProxmoxVE.git synced 2025-05-06 12:43:09 +00:00

Update docker-vm.sh

This commit is contained in:
CanbiZ 2025-05-05 22:17:27 +02:00
parent fd813b8936
commit 06960d3023

View File

@ -36,10 +36,30 @@ BGN=$(echo "\033[4;92m")
GN=$(echo "\033[1;92m") GN=$(echo "\033[1;92m")
DGN=$(echo "\033[32m") DGN=$(echo "\033[32m")
CL=$(echo "\033[m") CL=$(echo "\033[m")
CL=$(echo "\033[m")
BOLD=$(echo "\033[1m")
BFR="\\r\\033[K" BFR="\\r\\033[K"
HOLD="-" HOLD=" "
CM="${GN}${CL}" TAB=" "
CROSS="${RD}${CL}"
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}"
THIN="discard=on,ssd=1," THIN="discard=on,ssd=1,"
set -e set -e
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
@ -57,28 +77,29 @@ function error_handler() {
} }
function cleanup_vmid() { function cleanup_vmid() {
if qm status "$VMID" &>/dev/null; then if qm status $VMID &>/dev/null; then
qm stop "$VMID" &>/dev/null qm stop $VMID &>/dev/null
qm destroy "$VMID" &>/dev/null qm destroy $VMID &>/dev/null
fi fi
} }
function cleanup() { function cleanup() {
popd >/dev/null popd >/dev/null
rm -rf "$TEMP_DIR" post_update_to_api "done" "none"
rm -rf $TEMP_DIR
} }
TEMP_DIR=$(mktemp -d) 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 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 else
header_info && echo -e "⚠ User exited script \n" && exit header_info && echo -e "${CROSS}${RD}User exited script${CL}\n" && exit
fi fi
function msg_info() { function msg_info() {
local msg="$1" local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..." echo -ne "${TAB}${YW}${HOLD}${msg}${HOLD}"
} }
function msg_ok() { function msg_ok() {
@ -103,7 +124,7 @@ function check_root() {
function pve_check() { function pve_check() {
if ! pveversion | grep -Eq "pve-manager/8\.[1-4](\.[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" 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 "Requires Proxmox Virtual Environment Version 8.1 or later."
echo -e "Exiting..." echo -e "Exiting..."
sleep 2 sleep 2
@ -113,13 +134,12 @@ function pve_check() {
function arch_check() { function arch_check() {
if [ "$(dpkg --print-architecture)" != "amd64" ]; then if [ "$(dpkg --print-architecture)" != "amd64" ]; then
if [ "$(dpkg --print-architecture)" != "arm64" ]; then echo -e "\n ${INFO}${YWB}This script will not work with PiMox! \n"
msg_error "This script will not work with your CPU Architekture \n" echo -e "\n ${YWB}Visit https://github.com/asylumexp/Proxmox for ARM64 support. \n"
echo -e "Exiting..." echo -e "Exiting..."
sleep 2 sleep 2
exit exit
fi fi
fi
} }
function ssh_check() { function ssh_check() {
@ -176,7 +196,7 @@ function default_settings() {
function advanced_settings() { function advanced_settings() {
METHOD="advanced" METHOD="advanced"
while true; do 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 if [ -z "$VMID" ]; then
VMID="$NEXTID" VMID="$NEXTID"
fi fi
@ -185,7 +205,7 @@ function advanced_settings() {
sleep 2 sleep 2
continue continue
fi fi
echo -e "${DGN}Virtual Machine ID: ${BGN}$VMID${CL}" echo -e "${CONTAINERID}${BOLD}${DGN}Virtual Machine ID: ${BGN}$VMID${CL}"
break break
else else
exit-script exit-script
@ -196,12 +216,12 @@ function advanced_settings() {
"i440fx" "Machine i440fx" ON \ "i440fx" "Machine i440fx" ON \
"q35" "Machine q35" OFF \ "q35" "Machine q35" OFF \
3>&1 1>&2 2>&3); then 3>&1 1>&2 2>&3); then
if [ "$MACH" = q35 ]; then if [ $MACH = q35 ]; then
echo -e "${DGN}Using Machine Type: ${BGN}$MACH${CL}" echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}$MACH${CL}"
FORMAT="" FORMAT=""
MACHINE=" -machine q35" MACHINE=" -machine q35"
else else
echo -e "${DGN}Using Machine Type: ${BGN}$MACH${CL}" echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}$MACH${CL}"
FORMAT=",efitype=4m" FORMAT=",efitype=4m"
MACHINE="" MACHINE=""
fi fi
@ -224,28 +244,29 @@ function advanced_settings() {
exit-script exit-script
fi fi
if DISK_CACHE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISK CACHE" --radiolist "Choose" --cancel-button Exit-Script 10 58 2 \ if DISK_CACHE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "DISK CACHE" --radiolist "Choose" --cancel-button Exit-Script 10 58 2 \
"0" "None (Default)" ON \ "0" "None (Default)" ON \
"1" "Write Through" OFF \ "1" "Write Through" OFF \
3>&1 1>&2 2>&3); then 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}" echo -e "${DISKSIZE}${BOLD}${DGN}Disk Cache: ${BGN}Write Through${CL}"
DISK_CACHE="cache=writethrough," DISK_CACHE="cache=writethrough,"
else else
echo -e "${DGN}Using Disk Cache: ${BGN}None${CL}" echo -e "${DISKSIZE}${BOLD}${DGN}Disk Cache: ${BGN}None${CL}"
DISK_CACHE="" DISK_CACHE=""
fi fi
else else
exit-script exit-script
fi 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 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="docker" HN="debian"
echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}$HN${CL}"
else else
HN=$(echo "${VM_NAME,,}" | tr -d ' ') HN=$(echo ${VM_NAME,,} | tr -d ' ')
echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}" echo -e "${HOSTNAME}${BOLD}${DGN}Hostname: ${BGN}$HN${CL}"
fi fi
else else
exit-script exit-script
@ -255,11 +276,11 @@ function advanced_settings() {
"0" "KVM64 (Default)" ON \ "0" "KVM64 (Default)" ON \
"1" "Host" OFF \ "1" "Host" OFF \
3>&1 1>&2 2>&3); then 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}" echo -e "${OS}${BOLD}${DGN}CPU Model: ${BGN}Host${CL}"
CPU_TYPE=" -cpu host" CPU_TYPE=" -cpu host"
else else
echo -e "${DGN}Using CPU Model: ${BGN}KVM64${CL}" echo -e "${OS}${BOLD}${DGN}CPU Model: ${BGN}KVM64${CL}"
CPU_TYPE="" CPU_TYPE=""
fi fi
else else
@ -267,89 +288,89 @@ function advanced_settings() {
fi 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 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" CORE_COUNT="2"
echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}$CORE_COUNT${CL}"
else else
echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}" echo -e "${CPUCORE}${BOLD}${DGN}CPU Cores: ${BGN}$CORE_COUNT${CL}"
fi fi
else else
exit-script exit-script
fi 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 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="4096" RAM_SIZE="2048"
echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}$RAM_SIZE${CL}"
else else
echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}" echo -e "${RAMSIZE}${BOLD}${DGN}RAM Size: ${BGN}$RAM_SIZE${CL}"
fi fi
else else
exit-script exit-script
fi 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 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" BRG="vmbr0"
echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" echo -e "${BRIDGE}${BOLD}${DGN}Bridge: ${BGN}$BRG${CL}"
else else
echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}" echo -e "${BRIDGE}${BOLD}${DGN}Bridge: ${BGN}$BRG${CL}"
fi fi
else else
exit-script exit-script
fi 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 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 [ -z $MAC1 ]; then
MAC="$GEN_MAC" MAC="$GEN_MAC"
echo -e "${DGN}Using MAC Address: ${BGN}$MAC${CL}" echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}$MAC${CL}"
else else
MAC="$MAC1" MAC="$MAC1"
echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}" echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}$MAC1${CL}"
fi fi
else else
exit-script exit-script
fi 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 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" VLAN1="Default"
VLAN="" VLAN=""
echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" echo -e "${VLANTAG}${BOLD}${DGN}VLAN: ${BGN}$VLAN1${CL}"
else else
VLAN=",tag=$VLAN1" VLAN=",tag=$VLAN1"
echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}" echo -e "${VLANTAG}${BOLD}${DGN}VLAN: ${BGN}$VLAN1${CL}"
fi fi
else else
exit-script exit-script
fi 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 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" MTU1="Default"
MTU="" MTU=""
echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" echo -e "${DEFAULT}${BOLD}${DGN}Interface MTU Size: ${BGN}$MTU1${CL}"
else else
MTU=",mtu=$MTU1" MTU=",mtu=$MTU1"
echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}" echo -e "${DEFAULT}${BOLD}${DGN}Interface MTU Size: ${BGN}$MTU1${CL}"
fi fi
else else
exit-script exit-script
fi fi
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "START VIRTUAL MACHINE" --yesno "Start VM when completed?" 10 58); then if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "START VIRTUAL MACHINE" --yesno "Start VM when completed?" 10 58); then
echo -e "${DGN}Start VM when completed: ${BGN}yes${CL}" echo -e "${GATEWAY}${BOLD}${DGN}Start VM when completed: ${BGN}yes${CL}"
START_VM="yes" START_VM="yes"
else else
echo -e "${DGN}Start VM when completed: ${BGN}no${CL}" echo -e "${GATEWAY}${BOLD}${DGN}Start VM when completed: ${BGN}no${CL}"
START_VM="no" START_VM="no"
fi fi
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create a Docker VM?" --no-button Do-Over 10 58); then if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create a Debian 12 VM?" --no-button Do-Over 10 58); then
echo -e "${RD}Creating a Docker VM using the above advanced settings${CL}" echo -e "${CREATING}${BOLD}${DGN}Creating a Debian 12 VM using the above advanced settings${CL}"
else else
header_info header_info
echo -e "${RD}Using Advanced Settings${CL}" echo -e "${ADVANCED}${BOLD}${RD}Using Advanced Settings${CL}"
advanced_settings advanced_settings
fi fi
} }
@ -357,15 +378,14 @@ function advanced_settings() {
function start_script() { function start_script() {
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
header_info header_info
echo -e "${BL}Using Default Settings${CL}" echo -e "${DEFAULT}${BOLD}${BL}Using Default Settings${CL}"
default_settings default_settings
else else
header_info header_info
echo -e "${RD}Using Advanced Settings${CL}" echo -e "${ADVANCED}${BOLD}${RD}Using Advanced Settings${CL}"
advanced_settings advanced_settings
fi fi
} }
check_root check_root
arch_check arch_check
pve_check pve_check
@ -375,9 +395,9 @@ post_to_api_vm
msg_info "Validating Storage" msg_info "Validating Storage"
while read -r line; do while read -r line; do
TAG=$(echo "$line" | awk '{print $1}') TAG=$(echo $line | awk '{print $1}')
TYPE=$(echo "$line" | awk '{printf "%-10s", $2}') 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)}') FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '{printf( "%9sB", $6)}')
ITEM=" Type: $TYPE Free: $FREE " ITEM=" Type: $TYPE Free: $FREE "
OFFSET=2 OFFSET=2
if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
@ -407,7 +427,7 @@ sleep 2
msg_ok "${CL}${BL}${URL}${CL}" msg_ok "${CL}${BL}${URL}${CL}"
curl -f#SL -o "$(basename "$URL")" "$URL" curl -f#SL -o "$(basename "$URL")" "$URL"
echo -en "\e[1A\e[0K" echo -en "\e[1A\e[0K"
FILE=$(basename "$URL") FILE=$(basename $URL)
msg_ok "Downloaded ${CL}${BL}${FILE}${CL}" 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}')
@ -452,7 +472,7 @@ pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null
qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null
qm set $VMID \ qm set $VMID \
-efidisk0 ${DISK0_REF}${FORMAT} \ -efidisk0 ${DISK0_REF}${FORMAT} \
-scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=2G \ -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=${DISK_SIZE} \
-boot order=scsi0 \ -boot order=scsi0 \
-serial0 socket >/dev/null -serial0 socket >/dev/null
qm resize $VMID scsi0 8G >/dev/null qm resize $VMID scsi0 8G >/dev/null
@ -490,18 +510,18 @@ EOF
) )
qm set "$VMID" -description "$DESCRIPTION" >/dev/null qm set "$VMID" -description "$DESCRIPTION" >/dev/null
if [ -n "$DISK_SIZE" ]; then f [ -n "$DISK_SIZE" ]; then
msg_info "Resizing disk to $DISK_SIZE GB" 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 else
msg_info "Using default disk size of $DEFAULT_DISK_SIZE GB" 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 fi
msg_ok "Created a Docker VM ${CL}${BL}(${HN})" msg_ok "Created a Docker VM ${CL}${BL}(${HN})"
if [ "$START_VM" == "yes" ]; then if [ "$START_VM" == "yes" ]; then
msg_info "Starting Docker VM" msg_info "Starting Docker VM"
qm start "$VMID" qm start $VMID
msg_ok "Started Docker VM" msg_ok "Started Docker VM"
fi fi
post_update_to_api "done" "none" post_update_to_api "done" "none"