Compare commits

..

1 Commits

Author SHA1 Message Date
MickLesk c0eec305cc feat(build): add SDN vnet selection in advanced install
List Proxmox SDN vnets in the bridge step and use pct vnet= when selected.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-19 22:51:10 +02:00
+44 -98
View File
@@ -519,6 +519,19 @@ validate_bridge() {
return 0
}
# ------------------------------------------------------------------------------
# validate_sdn_vnet()
#
# - Validates that an SDN vnet exists in the cluster config
# ------------------------------------------------------------------------------
validate_sdn_vnet() {
local vnet="$1"
[[ -z "$vnet" ]] && return 1
[[ -f /etc/pve/sdn/vnets.cfg ]] && grep -qE "^vnet:[[:space:]]*${vnet}([[:space:]]|$)" /etc/pve/sdn/vnets.cfg && return 0
command -v pvesh &>/dev/null && pvesh get "/cluster/sdn/vnets/${vnet}" &>/dev/null && return 0
return 1
}
# ------------------------------------------------------------------------------
# validate_gateway_in_subnet()
#
@@ -964,6 +977,7 @@ base_settings() {
HN="$requested_hostname"
BRG=${var_brg:-"vmbr0"}
SDN_VNET=${var_sdn_vnet:-""}
NET=${var_net:-"dhcp"}
# Resolve IP range if NET contains a range (e.g., 192.168.1.100/24-192.168.1.200/24)
@@ -1075,7 +1089,7 @@ load_vars_file() {
var_gateway var_hostname var_ipv6_method var_mac var_mknod var_mount_fs var_mtu
var_net var_nesting var_ns var_os var_protection var_pw var_ram var_tags var_timezone var_tun var_unprivileged
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage var_searchdomain
var_post_install var_vzdump_after_install var_vzdump_storage
var_post_install var_sdn_vnet
)
# Whitelist check helper
@@ -1250,17 +1264,9 @@ load_vars_file() {
continue
fi
;;
var_vzdump_after_install)
if [[ "$var_val" != "yes" && "$var_val" != "no" ]]; then
msg_warn "Invalid vzdump_after_install '$var_val' in $file (must be yes/no), ignoring"
continue
fi
;;
var_vzdump_storage)
local _vz_storage_status
_vz_storage_status=$(pvesm status 2>/dev/null | awk -v s="$var_val" '$1 == s { print $3 }')
if [[ -n "$var_val" && -z "$_vz_storage_status" ]]; then
msg_warn "Storage '$var_val' from $file not found on this node, ignoring"
var_sdn_vnet)
if [[ -n "$var_val" ]] && ! validate_sdn_vnet "$var_val"; then
msg_warn "SDN vnet '$var_val' from $file not found, ignoring"
continue
fi
;;
@@ -1307,7 +1313,7 @@ default_var_settings() {
var_gateway var_hostname var_ipv6_method var_mac var_mknod var_mount_fs var_mtu
var_net var_nesting var_ns var_os var_protection var_pw var_ram var_tags var_timezone var_tun var_unprivileged
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage
var_post_install var_vzdump_after_install var_vzdump_storage
var_post_install var_sdn_vnet
)
# Snapshot: environment variables (highest precedence)
@@ -1408,10 +1414,6 @@ var_verbose=no
# Runs ON THE HOST after the container is fully provisioned.
# Available env vars: APP, NSAPP, CTID, IP, HN, STORAGE, BRG
# var_post_install=/opt/post-install/myhook.sh
# Optional vzdump backup after successful install (Proxmox host)
# var_vzdump_after_install=yes
# var_vzdump_storage=local
EOF
# Now choose storages (always prompt unless just one exists)
@@ -1490,7 +1492,7 @@ if ! declare -p VAR_WHITELIST >/dev/null 2>&1; then
var_gateway var_hostname var_ipv6_method var_mac var_mknod var_mount_fs var_mtu
var_net var_nesting var_ns var_os var_protection var_pw var_ram var_tags var_timezone var_tun var_unprivileged
var_verbose var_version var_vlan var_ssh var_ssh_authorized_key var_container_storage var_template_storage var_searchdomain
var_post_install var_vzdump_after_install var_vzdump_storage
var_post_install var_sdn_vnet
)
fi
@@ -1700,12 +1702,11 @@ _build_current_app_vars_tmp() {
[ -n "$_hostname" ] && echo "var_hostname=$(_sanitize_value "$_hostname")"
[ -n "$_searchdomain" ] && echo "var_searchdomain=$(_sanitize_value "$_searchdomain")"
[ -n "${var_sdn_vnet:-}" ] && echo "var_sdn_vnet=$(_sanitize_value "${var_sdn_vnet}")"
[ -n "$_tpl_storage" ] && echo "var_template_storage=$(_sanitize_value "$_tpl_storage")"
[ -n "$_ct_storage" ] && echo "var_container_storage=$(_sanitize_value "$_ct_storage")"
[ -n "${var_post_install:-}" ] && echo "var_post_install=$(_sanitize_value "${var_post_install}")"
[ -n "${var_vzdump_after_install:-}" ] && echo "var_vzdump_after_install=$(_sanitize_value "${var_vzdump_after_install}")"
[ -n "${var_vzdump_storage:-}" ] && echo "var_vzdump_storage=$(_sanitize_value "${var_vzdump_storage}")"
} >"$tmpf"
echo "$tmpf"
@@ -1850,7 +1851,7 @@ advanced_settings() {
TAGS="community-script${var_tags:+;${var_tags}}"
fi
local STEP=1
local MAX_STEP=30
local MAX_STEP=29
# Store values for back navigation - inherit from var_* app defaults
local _ct_type="${var_unprivileged:-1}"
@@ -1862,6 +1863,7 @@ advanced_settings() {
local _core_count="${var_cpu:-1}"
local _ram_size="${var_ram:-1024}"
local _bridge="${var_brg:-vmbr0}"
local _sdn_vnet="${var_sdn_vnet:-}"
local _net="${var_net:-dhcp}"
local _gate="${var_gateway:-}"
local _ipv6_method="${var_ipv6_method:-auto}"
@@ -1885,8 +1887,6 @@ advanced_settings() {
local _mount_fs="${var_mount_fs:-}"
local _protect_ct="${var_protection:-no}"
local _post_install="${var_post_install:-}"
local _vzdump="${var_vzdump_after_install:-no}"
local _vzdump_storage="${var_vzdump_storage:-}"
# Detect host timezone for default (if not set via var_timezone)
local _host_timezone=""
@@ -1943,6 +1943,11 @@ advanced_settings() {
fi
done <<<"$BRIDGES"
fi
if [[ -f /etc/pve/sdn/vnets.cfg ]]; then
while IFS= read -r vnet; do
[[ -n "$vnet" ]] && BRIDGE_MENU_OPTIONS+=("sdn:${vnet}" "[SDN] ${vnet}")
done < <(awk '/^vnet:/{print $2}' /etc/pve/sdn/vnets.cfg 2>/dev/null)
fi
}
_detect_bridges
@@ -2175,8 +2180,18 @@ advanced_settings() {
if [[ "$bridge_test" == "__other__" || "$bridge_test" == -* ]]; then
continue
fi
if validate_bridge "$bridge_test"; then
if [[ "$bridge_test" == sdn:* ]]; then
local vnet_test="${bridge_test#sdn:}"
if validate_sdn_vnet "$vnet_test"; then
_sdn_vnet="$vnet_test"
_bridge="${var_brg:-vmbr0}"
((STEP++))
else
whiptail --msgbox "SDN vnet '$vnet_test' is not configured on this cluster." 8 58
fi
elif validate_bridge "$bridge_test"; then
_bridge="$bridge_test"
_sdn_vnet=""
((STEP++))
else
whiptail --msgbox "Bridge '$bridge_test' is not available or not active." 8 58
@@ -2796,58 +2811,9 @@ Leave empty to skip."
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 29: Optional vzdump backup after install
# STEP 29: Verbose Mode & Confirmation
# ═══════════════════════════════════════════════════════════════════════════
29)
local vzdump_default_flag="--defaultno"
[[ "$_vzdump" == "yes" ]] && vzdump_default_flag=""
if whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "POST-INSTALL VZDUMP" \
--ok-button "Next" --cancel-button "Back" \
$vzdump_default_flag \
--yesno "\nCreate a vzdump backup after successful install?\n\nRuns on the Proxmox host once the container is ready.\n\n(App default: ${var_vzdump_after_install:-no})" 14 62; then
_vzdump="yes"
local _storages _menu_items=() _s
_storages=$(awk '
/^[a-z]+:/ { if (name != "") { if (has_backup || (!has_content && type == "dir")) print name }
split($0,a,":"); type=a[1]; name=a[2]; gsub(/^[ \t]+|[ \t]+$/, "", name); has_content=0; has_backup=0 }
/^[ \t]*content/ { has_content=1; if ($0 ~ /backup/) has_backup=1 }
END { if (name != "") { if (has_backup || (!has_content && type == "dir")) print name } }
' /etc/pve/storage.cfg 2>/dev/null)
if [[ -n "$_storages" ]]; then
while IFS= read -r _s; do
[[ -n "$_s" ]] && _menu_items+=("$_s" " ")
done <<<"$_storages"
if result=$(whiptail --backtitle "Proxmox VE Helper Scripts [Step $STEP/$MAX_STEP]" \
--title "VZDUMP STORAGE" \
--ok-button "Next" --cancel-button "Back" \
--menu "\nSelect backup storage:" 16 58 8 \
"${_menu_items[@]}" \
3>&1 1>&2 2>&3); then
_vzdump_storage="$result"
fi
else
whiptail --msgbox "No backup-capable storage found.\n\nConfigure storage with 'backup' content in Proxmox first." 10 58
_vzdump="no"
_vzdump_storage=""
fi
else
if [ $? -eq 1 ]; then
_vzdump="no"
_vzdump_storage=""
else
((STEP--))
continue
fi
fi
((STEP++))
;;
# ═══════════════════════════════════════════════════════════════════════════
# STEP 30: Verbose Mode & Confirmation
# ═══════════════════════════════════════════════════════════════════════════
30)
local verbose_default_flag="--defaultno"
[[ "$_verbose" == "yes" ]] && verbose_default_flag=""
@@ -2949,8 +2915,6 @@ Advanced:
APT_CACHER_IP="$_apt_cacher_ip"
VERBOSE="$_verbose"
var_post_install="$_post_install"
var_vzdump_after_install="$_vzdump"
var_vzdump_storage="$_vzdump_storage"
# Update var_* based on user choice (for functions that check these)
var_gpu="$_enable_gpu"
@@ -2964,6 +2928,7 @@ Advanced:
var_timezone="$_ct_timezone"
var_apt_cacher="$_apt_cacher"
var_apt_cacher_ip="$_apt_cacher_ip"
var_sdn_vnet="$_sdn_vnet"
# Format optional values
[[ -n "$_mtu" ]] && MTU=",mtu=$_mtu" || MTU=""
@@ -3855,6 +3820,9 @@ build_container() {
# if [ "$VERBOSE" == "yes" ]; then set -x; fi
NET_STRING="-net0 name=eth0,bridge=${BRG:-vmbr0}"
if [[ -n "${var_sdn_vnet:-${SDN_VNET:-}}" ]]; then
NET_STRING="-net0 name=eth0,vnet=${var_sdn_vnet:-$SDN_VNET}"
fi
# MAC
if [[ -n "$MAC" ]]; then
@@ -6658,26 +6626,6 @@ create_lxc_container() {
# SECTION 9: POST-INSTALLATION & FINALIZATION
# ==============================================================================
# ------------------------------------------------------------------------------
# _run_post_install_vzdump()
#
# - Optional vzdump on the Proxmox host after a successful install
# - Controlled by var_vzdump_after_install / var_vzdump_storage
# ------------------------------------------------------------------------------
_run_post_install_vzdump() {
[[ "${var_vzdump_after_install:-no}" != "yes" ]] && return 0
[[ -z "${CTID:-}" ]] && return 0
local storage="${var_vzdump_storage:-${CONTAINER_STORAGE:-local}}"
msg_info "Creating post-install vzdump backup (CT ${CTID}${storage})"
if vzdump "$CTID" --mode snapshot --compress zstd --storage "$storage" \
--notes-template "community-scripts post-install - ${APP:-LXC}" >>"${BUILD_LOG:-/dev/null}" 2>&1; then
msg_ok "Post-install vzdump created on ${storage}"
else
msg_warn "Post-install vzdump failed (storage: ${storage})"
fi
}
# ------------------------------------------------------------------------------
# description()
#
@@ -6776,8 +6724,6 @@ EOF
fi
fi
_run_post_install_vzdump
INSTALL_COMPLETE=true
post_update_to_api "done" "none"
}