Update umbrel-os-vm.sh

This commit is contained in:
CanbiZ 2025-05-26 10:37:12 +02:00
parent 3652351b28
commit b62f5bf0b4

View File

@ -20,13 +20,11 @@ EOF
header_info header_info
echo -e "\n Loading..." echo -e "\n Loading..."
GEN_MAC=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//') 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)" RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
METHOD="" METHOD=""
NSAPP="umbrel-os-vm" NSAPP="umbrel-os-vm"
var_os="debian" var_os="debian"
var_version="12" var_version="12"
DISK_SIZE="32G"
YW=$(echo "\033[33m") YW=$(echo "\033[33m")
BL=$(echo "\033[36m") BL=$(echo "\033[36m")
@ -76,6 +74,23 @@ function error_handler() {
cleanup_vmid 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() { 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
@ -162,12 +177,12 @@ function exit_script() {
} }
function default_settings() { function default_settings() {
VMID="$NEXTID" VMID=$(get_valid_nextid)
FORMAT=",efitype=4m" FORMAT=",efitype=4m"
MACHINE="" MACHINE=""
DISK_CACHE="" DISK_CACHE=""
DISK_SIZE="8G" DISK_SIZE="32G"
HN="docker" HN="umbrel-os"
CPU_TYPE="" CPU_TYPE=""
CORE_COUNT="2" CORE_COUNT="2"
RAM_SIZE="4096" RAM_SIZE="4096"
@ -195,10 +210,11 @@ function default_settings() {
function advanced_settings() { function advanced_settings() {
METHOD="advanced" METHOD="advanced"
[ -z "${VMID:-}" ] && VMID=$(get_valid_nextid)
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 $VMID --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=$(get_valid_nextid)
fi fi
if pct status "$VMID" &>/dev/null || qm status "$VMID" &>/dev/null; then if pct status "$VMID" &>/dev/null || qm status "$VMID" &>/dev/null; then
echo -e "${CROSS}${RD} ID $VMID is already in use${CL}" 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}" echo -e "${CONTAINERID}${BOLD}${DGN}Virtual Machine ID: ${BGN}$VMID${CL}"
break break
else else
exit_script exit-script
fi fi
done done