From b62f5bf0b4ab49e20a35825b4f71278ccbd62c71 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 26 May 2025 10:37:12 +0200 Subject: [PATCH] Update umbrel-os-vm.sh --- vm/umbrel-os-vm.sh | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/vm/umbrel-os-vm.sh b/vm/umbrel-os-vm.sh index aeb988b..101973b 100644 --- a/vm/umbrel-os-vm.sh +++ b/vm/umbrel-os-vm.sh @@ -20,13 +20,11 @@ EOF header_info echo -e "\n Loading..." GEN_MAC=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//') -NEXTID=$(pvesh get /cluster/nextid) RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)" METHOD="" NSAPP="umbrel-os-vm" var_os="debian" var_version="12" -DISK_SIZE="32G" YW=$(echo "\033[33m") BL=$(echo "\033[36m") @@ -76,6 +74,23 @@ function error_handler() { cleanup_vmid } +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" +} + function cleanup_vmid() { if qm status $VMID &>/dev/null; then qm stop $VMID &>/dev/null @@ -162,12 +177,12 @@ function exit_script() { } function default_settings() { - VMID="$NEXTID" + VMID=$(get_valid_nextid) FORMAT=",efitype=4m" MACHINE="" DISK_CACHE="" - DISK_SIZE="8G" - HN="docker" + DISK_SIZE="32G" + HN="umbrel-os" CPU_TYPE="" CORE_COUNT="2" RAM_SIZE="4096" @@ -195,10 +210,11 @@ function default_settings() { function advanced_settings() { METHOD="advanced" + [ -z "${VMID:-}" ] && VMID=$(get_valid_nextid) 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 $VMID --title "VIRTUAL MACHINE ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3); then if [ -z "$VMID" ]; then - VMID="$NEXTID" + VMID=$(get_valid_nextid) fi if pct status "$VMID" &>/dev/null || qm status "$VMID" &>/dev/null; then echo -e "${CROSS}${RD} ID $VMID is already in use${CL}" @@ -208,7 +224,7 @@ function advanced_settings() { echo -e "${CONTAINERID}${BOLD}${DGN}Virtual Machine ID: ${BGN}$VMID${CL}" break else - exit_script + exit-script fi done