mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-05-08 21:03:09 +00:00
Feature: get correct next VMID (#4292)
fix(vm-creation): ensure whiptail VMID inputbox is pre-filled with a valid and available ID - Replaced hardcoded NEXTID usage with a new get_valid_nextid() function - Ensures no collision with existing VMs, LXCs or orphaned LVM volumes - Improves user experience by properly pre-filling whiptail inputbox - Automatically skips invalid IDs instead of failing on alloc
This commit is contained in:
parent
ebc17e120e
commit
c9aad3a54d
@ -26,7 +26,6 @@ NSAPP="arch-linux-vm"
|
|||||||
var_os="arch-linux"
|
var_os="arch-linux"
|
||||||
var_version=" "
|
var_version=" "
|
||||||
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)
|
|
||||||
|
|
||||||
YW=$(echo "\033[33m")
|
YW=$(echo "\033[33m")
|
||||||
BL=$(echo "\033[36m")
|
BL=$(echo "\033[36m")
|
||||||
@ -76,6 +75,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
|
||||||
@ -161,7 +177,7 @@ function exit-script() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function default_settings() {
|
function default_settings() {
|
||||||
VMID="$NEXTID"
|
VMID=$(get_valid_nextid)
|
||||||
FORMAT=",efitype=4m"
|
FORMAT=",efitype=4m"
|
||||||
MACHINE=""
|
MACHINE=""
|
||||||
DISK_SIZE="4G"
|
DISK_SIZE="4G"
|
||||||
@ -194,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}"
|
||||||
|
@ -20,7 +20,6 @@ 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="debian12vm"
|
NSAPP="debian12vm"
|
||||||
@ -75,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
|
||||||
@ -161,7 +177,7 @@ function exit-script() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function default_settings() {
|
function default_settings() {
|
||||||
VMID="$NEXTID"
|
VMID=$(get_valid_nextid)
|
||||||
FORMAT=",efitype=4m"
|
FORMAT=",efitype=4m"
|
||||||
MACHINE=""
|
MACHINE=""
|
||||||
DISK_SIZE="8G"
|
DISK_SIZE="8G"
|
||||||
@ -194,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}"
|
||||||
|
@ -20,7 +20,6 @@ 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="debian12vm"
|
NSAPP="debian12vm"
|
||||||
@ -76,6 +75,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,7 +178,7 @@ 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=""
|
||||||
@ -195,10 +211,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}"
|
||||||
@ -244,7 +261,6 @@ 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 \
|
||||||
|
@ -21,15 +21,13 @@ 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)
|
|
||||||
VERSIONS=(stable beta dev)
|
VERSIONS=(stable beta dev)
|
||||||
#API VARIABLES
|
|
||||||
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
||||||
METHOD=""
|
METHOD=""
|
||||||
NSAPP="homeassistant-os"
|
NSAPP="homeassistant-os"
|
||||||
var_os="homeassistant"
|
var_os="homeassistant"
|
||||||
DISK_SIZE="32G"
|
DISK_SIZE="32G"
|
||||||
#
|
|
||||||
for version in "${VERSIONS[@]}"; do
|
for version in "${VERSIONS[@]}"; do
|
||||||
eval "$version=$(curl -fsSL https://raw.githubusercontent.com/home-assistant/version/master/stable.json | grep '"ova"' | cut -d '"' -f 4)"
|
eval "$version=$(curl -fsSL https://raw.githubusercontent.com/home-assistant/version/master/stable.json | grep '"ova"' | cut -d '"' -f 4)"
|
||||||
done
|
done
|
||||||
@ -65,6 +63,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
|
||||||
@ -166,7 +181,7 @@ function exit-script() {
|
|||||||
|
|
||||||
function default_settings() {
|
function default_settings() {
|
||||||
BRANCH="$stable"
|
BRANCH="$stable"
|
||||||
VMID="$NEXTID"
|
VMID=$(get_valid_nextid)
|
||||||
FORMAT=",efitype=4m"
|
FORMAT=",efitype=4m"
|
||||||
MACHINE=""
|
MACHINE=""
|
||||||
DISK_CACHE="cache=writethrough,"
|
DISK_CACHE="cache=writethrough,"
|
||||||
@ -210,10 +225,11 @@ function advanced_settings() {
|
|||||||
exit-script
|
exit-script
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[ -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="$VMID"
|
||||||
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}"
|
||||||
|
@ -21,15 +21,12 @@ clear
|
|||||||
header_info
|
header_info
|
||||||
echo -e "Loading..."
|
echo -e "Loading..."
|
||||||
GEN_MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]')
|
GEN_MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]')
|
||||||
NEXTID=$(pvesh get /cluster/nextid)
|
|
||||||
#API VARIABLES
|
|
||||||
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
||||||
METHOD=""
|
METHOD=""
|
||||||
NSAPP="mikrotik-router-os"
|
NSAPP="mikrotik-router-os"
|
||||||
var_os="mikrotik"
|
var_os="mikrotik"
|
||||||
var_version=" "
|
var_version=" "
|
||||||
DISK_SIZE="1G"
|
DISK_SIZE="1G"
|
||||||
#
|
|
||||||
YW=$(echo "\033[33m")
|
YW=$(echo "\033[33m")
|
||||||
BL=$(echo "\033[36m")
|
BL=$(echo "\033[36m")
|
||||||
HA=$(echo "\033[1;34m")
|
HA=$(echo "\033[1;34m")
|
||||||
@ -60,6 +57,24 @@ function error_exit() {
|
|||||||
[ ! -z ${VMID-} ] && cleanup_vmid
|
[ ! -z ${VMID-} ] && cleanup_vmid
|
||||||
exit $EXIT
|
exit $EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then
|
if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then
|
||||||
|
@ -19,16 +19,13 @@ EOF
|
|||||||
}
|
}
|
||||||
header_info
|
header_info
|
||||||
echo -e "\n Loading..."
|
echo -e "\n Loading..."
|
||||||
#API VARIABLES
|
|
||||||
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
||||||
METHOD=""
|
METHOD=""
|
||||||
NSAPP="turnkey-nextcloud"
|
NSAPP="turnkey-nextcloud"
|
||||||
var_os="turnkey-nextcloud"
|
var_os="turnkey-nextcloud"
|
||||||
var_version=" "
|
var_version=" "
|
||||||
DISK_SIZE="12G"
|
DISK_SIZE="12G"
|
||||||
#
|
|
||||||
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)
|
|
||||||
NAME="TurnKey Nexcloud VM"
|
NAME="TurnKey Nexcloud VM"
|
||||||
YW=$(echo "\033[33m")
|
YW=$(echo "\033[33m")
|
||||||
BL=$(echo "\033[36m")
|
BL=$(echo "\033[36m")
|
||||||
@ -58,6 +55,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
|
||||||
@ -142,7 +156,7 @@ 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=""
|
||||||
@ -173,10 +187,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}"
|
||||||
|
@ -23,17 +23,15 @@ EOF
|
|||||||
}
|
}
|
||||||
header_info
|
header_info
|
||||||
echo -e "Loading..."
|
echo -e "Loading..."
|
||||||
#API VARIABLES
|
|
||||||
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
||||||
METHOD=""
|
METHOD=""
|
||||||
NSAPP="openwrt-vm"
|
NSAPP="openwrt-vm"
|
||||||
var_os="openwrt"
|
var_os="openwrt"
|
||||||
var_version=" "
|
var_version=" "
|
||||||
DISK_SIZE="0.5G"
|
DISK_SIZE="0.5G"
|
||||||
#
|
|
||||||
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/.$//')
|
||||||
GEN_MAC_LAN=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//')
|
GEN_MAC_LAN=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//')
|
||||||
NEXTID=$(pvesh get /cluster/nextid)
|
|
||||||
YW=$(echo "\033[33m")
|
YW=$(echo "\033[33m")
|
||||||
BL=$(echo "\033[36m")
|
BL=$(echo "\033[36m")
|
||||||
HA=$(echo "\033[1;34m")
|
HA=$(echo "\033[1;34m")
|
||||||
@ -61,6 +59,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
|
||||||
@ -242,10 +257,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}"
|
||||||
|
@ -28,7 +28,7 @@ var_version="25.1"
|
|||||||
#
|
#
|
||||||
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/.$//')
|
||||||
GEN_MAC_LAN=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//')
|
GEN_MAC_LAN=02:$(openssl rand -hex 5 | awk '{print toupper($0)}' | sed 's/\(..\)/\1:/g; s/.$//')
|
||||||
NEXTID=$(pvesh get /cluster/nextid)
|
|
||||||
YW=$(echo "\033[33m")
|
YW=$(echo "\033[33m")
|
||||||
BL=$(echo "\033[36m")
|
BL=$(echo "\033[36m")
|
||||||
HA=$(echo "\033[1;34m")
|
HA=$(echo "\033[1;34m")
|
||||||
@ -54,6 +54,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
|
||||||
@ -202,7 +219,7 @@ 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=""
|
||||||
@ -252,10 +269,11 @@ function default_settings() {
|
|||||||
function advanced_settings() {
|
function advanced_settings() {
|
||||||
local ip_regex='^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$'
|
local ip_regex='^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$'
|
||||||
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}"
|
||||||
|
@ -19,17 +19,15 @@ EOF
|
|||||||
}
|
}
|
||||||
header_info
|
header_info
|
||||||
echo -e "\n Loading..."
|
echo -e "\n Loading..."
|
||||||
#API VARIABLES
|
|
||||||
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
||||||
METHOD=""
|
METHOD=""
|
||||||
NSAPP="turnkey-owncloud-vm"
|
NSAPP="turnkey-owncloud-vm"
|
||||||
var_os="owncloud"
|
var_os="owncloud"
|
||||||
var_version="12"
|
var_version="12"
|
||||||
DISK_SIZE="12G"
|
DISK_SIZE="12G"
|
||||||
#
|
|
||||||
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)
|
|
||||||
NAME="TurnKey ownCloud VM"
|
NAME="TurnKey ownCloud VM"
|
||||||
|
|
||||||
YW=$(echo "\033[33m")
|
YW=$(echo "\033[33m")
|
||||||
BL=$(echo "\033[36m")
|
BL=$(echo "\033[36m")
|
||||||
HA=$(echo "\033[1;34m")
|
HA=$(echo "\033[1;34m")
|
||||||
@ -58,6 +56,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
|
||||||
@ -142,7 +157,7 @@ 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=""
|
||||||
@ -173,10 +188,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}"
|
||||||
|
@ -24,17 +24,14 @@ EOF
|
|||||||
clear
|
clear
|
||||||
header_info
|
header_info
|
||||||
echo -e "Loading..."
|
echo -e "Loading..."
|
||||||
#API VARIABLES
|
|
||||||
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
RANDOM_UUID="$(cat /proc/sys/kernel/random/uuid)"
|
||||||
METHOD=""
|
METHOD=""
|
||||||
NSAPP="pimox-haos-vm"
|
NSAPP="pimox-haos-vm"
|
||||||
var_os="pimox-haos"
|
var_os="pimox-haos"
|
||||||
var_version=" "
|
var_version=" "
|
||||||
DISK_SIZE="32G"
|
DISK_SIZE="32G"
|
||||||
#
|
|
||||||
GEN_MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]')
|
GEN_MAC=$(echo '00 60 2f'$(od -An -N3 -t xC /dev/urandom) | sed -e 's/ /:/g' | tr '[:lower:]' '[:upper:]')
|
||||||
USEDID=$(pvesh get /cluster/resources --type vm --output-format yaml | egrep -i 'vmid' | awk '{print substr($2, 1, length($2)-0) }')
|
USEDID=$(pvesh get /cluster/resources --type vm --output-format yaml | egrep -i 'vmid' | awk '{print substr($2, 1, length($2)-0) }')
|
||||||
NEXTID=$(pvesh get /cluster/nextid)
|
|
||||||
STABLE=$(curl -fsSL https://raw.githubusercontent.com/home-assistant/version/master/stable.json | grep "ova" | awk '{print substr($2, 2, length($2)-3) }')
|
STABLE=$(curl -fsSL https://raw.githubusercontent.com/home-assistant/version/master/stable.json | grep "ova" | awk '{print substr($2, 2, length($2)-3) }')
|
||||||
BETA=$(curl -fsSL https://raw.githubusercontent.com/home-assistant/version/master/beta.json | grep "ova" | awk '{print substr($2, 2, length($2)-3) }')
|
BETA=$(curl -fsSL https://raw.githubusercontent.com/home-assistant/version/master/beta.json | grep "ova" | awk '{print substr($2, 2, length($2)-3) }')
|
||||||
DEV=$(curl -fsSL https://raw.githubusercontent.com/home-assistant/version/master/dev.json | grep "ova" | awk '{print substr($2, 2, length($2)-3) }')
|
DEV=$(curl -fsSL https://raw.githubusercontent.com/home-assistant/version/master/dev.json | grep "ova" | awk '{print substr($2, 2, length($2)-3) }')
|
||||||
@ -70,6 +67,24 @@ function error_exit() {
|
|||||||
[ ! -z ${VMID-} ] && cleanup_vmid
|
[ ! -z ${VMID-} ] && cleanup_vmid
|
||||||
exit $EXIT
|
exit $EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then
|
if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then
|
||||||
|
@ -20,7 +20,6 @@ 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="ubuntu-2204-vm"
|
NSAPP="ubuntu-2204-vm"
|
||||||
@ -33,8 +32,6 @@ RD=$(echo "\033[01;31m")
|
|||||||
BGN=$(echo "\033[4;92m")
|
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")
|
BOLD=$(echo "\033[1m")
|
||||||
BFR="\\r\\033[K"
|
BFR="\\r\\033[K"
|
||||||
@ -75,6 +72,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
|
||||||
@ -160,7 +174,7 @@ function exit-script() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function default_settings() {
|
function default_settings() {
|
||||||
VMID="$NEXTID"
|
VMID=$(get_valid_nextid)
|
||||||
FORMAT=",efitype=4m"
|
FORMAT=",efitype=4m"
|
||||||
MACHINE=""
|
MACHINE=""
|
||||||
DISK_SIZE="5G"
|
DISK_SIZE="5G"
|
||||||
@ -193,10 +207,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}"
|
||||||
|
@ -21,7 +21,6 @@ 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="ubuntu-2404-vm"
|
NSAPP="ubuntu-2404-vm"
|
||||||
@ -76,6 +75,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
|
||||||
@ -161,7 +177,7 @@ function exit-script() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function default_settings() {
|
function default_settings() {
|
||||||
VMID="$NEXTID"
|
VMID=$(get_valid_nextid)
|
||||||
FORMAT=",efitype=4m"
|
FORMAT=",efitype=4m"
|
||||||
MACHINE=""
|
MACHINE=""
|
||||||
DISK_SIZE="7G"
|
DISK_SIZE="7G"
|
||||||
@ -194,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}"
|
||||||
|
@ -20,7 +20,6 @@ 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="ubuntu-2410-vm"
|
NSAPP="ubuntu-2410-vm"
|
||||||
@ -75,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
|
||||||
@ -160,7 +176,7 @@ function exit-script() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function default_settings() {
|
function default_settings() {
|
||||||
VMID="$NEXTID"
|
VMID=$(get_valid_nextid)
|
||||||
FORMAT=",efitype=4m"
|
FORMAT=",efitype=4m"
|
||||||
MACHINE=""
|
MACHINE=""
|
||||||
DISK_SIZE="8G"
|
DISK_SIZE="8G"
|
||||||
@ -193,10 +209,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}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user