Update build.func

This commit is contained in:
CanbiZ 2025-09-16 13:06:13 +02:00
parent 6ca38e23ae
commit d6a1183824

View File

@ -1581,6 +1581,92 @@ install_script() {
esac
}
# Check and prompt for storage if missing or invalid
check_storage_or_prompt() {
local vars_file="$1"
local changed=0
if [[ ! -f "$vars_file" ]]; then
msg_warn "No vars file found at $vars_file"
return 1
fi
# Helper: validate storage
_validate_storage() {
local s="$1"
[[ -n "$s" ]] || return 1
pvesm status -content images | awk 'NR>1 {print $1}' | grep -qx "$s"
}
# Load current values
local ct_store tpl_store
ct_store="$(grep -E '^var_container_storage=' "$vars_file" | cut -d= -f2-)"
tpl_store="$(grep -E '^var_template_storage=' "$vars_file" | cut -d= -f2-)"
# Container storage
if ! _validate_storage "$ct_store"; then
local new_ct
new_ct=$(pvesm status -content images | awk 'NR>1 {print $1" "$2" "$6}')
new_ct=$(whiptail --backtitle "[dev] Proxmox VE Helper Scripts" \
--title "Select Container Storage" \
--menu "Choose container storage:" 20 60 10 $new_ct 3>&1 1>&2 2>&3) || return 1
if [[ -n "$new_ct" ]]; then
sed -i "/^var_container_storage=/d" "$vars_file"
echo "var_container_storage=$new_ct" >>"$vars_file"
changed=1
msg_ok "Updated container storage in $vars_file → $new_ct"
fi
fi
# Template storage
if ! _validate_storage "$tpl_store"; then
local new_tpl
new_tpl=$(pvesm status -content vztmpl | awk 'NR>1 {print $1" "$2" "$6}')
new_tpl=$(whiptail --backtitle "[dev] Proxmox VE Helper Scripts" \
--title "Select Template Storage" \
--menu "Choose template storage:" 20 60 10 $new_tpl 3>&1 1>&2 2>&3) || return 1
if [[ -n "$new_tpl" ]]; then
sed -i "/^var_template_storage=/d" "$vars_file"
echo "var_template_storage=$new_tpl" >>"$vars_file"
changed=1
msg_ok "Updated template storage in $vars_file → $new_tpl"
fi
fi
return $changed
}
# Storage Settings menu
storage_settings_menu() {
local menu_items=(
"1" "Check & update My Defaults (default.vars)"
)
if [ -f "$(get_app_defaults_path)" ]; then
menu_items+=("2" "Check & update App Defaults for ${APP}")
fi
menu_items+=("3" "Back")
local choice
choice=$(whiptail --backtitle "[dev] Proxmox VE Helper Scripts" \
--title "STORAGE SETTINGS" \
--menu "Select what to update:" 15 60 5 \
"${menu_items[@]}" 3>&1 1>&2 2>&3) || return 0
case "$choice" in
1)
check_storage_or_prompt "/usr/local/community-scripts/default.vars"
;;
2)
if [ -f "$(get_app_defaults_path)" ]; then
check_storage_or_prompt "$(get_app_defaults_path)"
fi
;;
3)
return 0
;;
esac
}
check_container_resources() {
# Check actual RAM & Cores