mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-06-20 14:31:18 +02:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e99ad6409f |
+30
-103
@@ -1075,7 +1075,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
|
||||
)
|
||||
|
||||
# Whitelist check helper
|
||||
@@ -1250,20 +1250,6 @@ 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"
|
||||
continue
|
||||
fi
|
||||
;;
|
||||
var_container_storage | var_template_storage)
|
||||
# Validate that the storage exists and is active on the current node
|
||||
local _storage_status
|
||||
@@ -1307,7 +1293,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
|
||||
)
|
||||
|
||||
# Snapshot: environment variables (highest precedence)
|
||||
@@ -1408,10 +1394,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 +1472,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
|
||||
)
|
||||
fi
|
||||
|
||||
@@ -1704,8 +1686,6 @@ _build_current_app_vars_tmp() {
|
||||
[ -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 +1830,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}"
|
||||
@@ -1885,8 +1865,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=""
|
||||
@@ -2796,58 +2774,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 +2878,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"
|
||||
@@ -3765,6 +3692,28 @@ runtime_script_status_guard() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# _run_update_script()
|
||||
#
|
||||
# - Runs update_script inside the LXC with standardized backup recovery
|
||||
# - create_backup() arms an ERR trap; successful updates clear the backup store
|
||||
# - Works even when update_script ends with exit (EXIT trap)
|
||||
# ------------------------------------------------------------------------------
|
||||
_run_update_script() {
|
||||
local _update_rc=0
|
||||
_on_update_script_exit() {
|
||||
local _exit_rc=$?
|
||||
trap - EXIT
|
||||
if [[ $_exit_rc -eq 0 ]] && declare -f clear_update_backup &>/dev/null; then
|
||||
clear_update_backup
|
||||
fi
|
||||
exit "$_exit_rc"
|
||||
}
|
||||
trap '_on_update_script_exit' EXIT
|
||||
update_script || _update_rc=$?
|
||||
return "$_update_rc"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# start()
|
||||
#
|
||||
@@ -3786,7 +3735,7 @@ start() {
|
||||
ensure_profile_loaded
|
||||
get_lxc_ip
|
||||
runtime_script_status_guard || return 0
|
||||
update_script
|
||||
_run_update_script
|
||||
run_addon_updates
|
||||
update_motd_ip
|
||||
cleanup_lxc
|
||||
@@ -3797,7 +3746,7 @@ start() {
|
||||
ensure_profile_loaded
|
||||
get_lxc_ip
|
||||
runtime_script_status_guard || return 0
|
||||
update_script
|
||||
_run_update_script
|
||||
run_addon_updates
|
||||
update_motd_ip
|
||||
cleanup_lxc
|
||||
@@ -3827,7 +3776,7 @@ start() {
|
||||
ensure_profile_loaded
|
||||
get_lxc_ip
|
||||
runtime_script_status_guard || return 0
|
||||
update_script
|
||||
_run_update_script
|
||||
run_addon_updates
|
||||
update_motd_ip
|
||||
cleanup_lxc
|
||||
@@ -6658,26 +6607,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 +6705,6 @@ EOF
|
||||
fi
|
||||
fi
|
||||
|
||||
_run_post_install_vzdump
|
||||
|
||||
INSTALL_COMPLETE=true
|
||||
post_update_to_api "done" "none"
|
||||
}
|
||||
|
||||
@@ -1162,6 +1162,7 @@ create_backup() {
|
||||
|
||||
if [[ -f "$manifest" ]]; then
|
||||
msg_ok "Existing backup found at ${store}, skipping backup"
|
||||
trap '_restore_update_backup_on_error' ERR
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -1186,6 +1187,24 @@ create_backup() {
|
||||
echo "$path" >>"$manifest"
|
||||
done
|
||||
msg_ok "Backed up data to ${store}"
|
||||
trap '_restore_update_backup_on_error' ERR
|
||||
}
|
||||
|
||||
_restore_update_backup_on_error() {
|
||||
local _err=$?
|
||||
trap - ERR
|
||||
if [[ -f "${BACKUP_DIR:-/opt/${NSAPP:-app}.backup}/.manifest" ]]; then
|
||||
msg_error "Update failed (exit ${_err}) – restoring backup"
|
||||
restore_backup
|
||||
fi
|
||||
exit "${_err:-1}"
|
||||
}
|
||||
|
||||
clear_update_backup() {
|
||||
local store="${BACKUP_DIR:-/opt/${NSAPP:-app}.backup}"
|
||||
[[ -d "$store" ]] || return 0
|
||||
rm -rf "$store"
|
||||
trap - ERR
|
||||
}
|
||||
|
||||
restore_backup() {
|
||||
@@ -1208,6 +1227,7 @@ restore_backup() {
|
||||
cp -a "$src" "$path"
|
||||
done <"$manifest"
|
||||
rm -rf "$store"
|
||||
trap - ERR
|
||||
msg_ok "Restored data"
|
||||
}
|
||||
|
||||
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (c) 2021-2026 community-scripts ORG
|
||||
# License: MIT
|
||||
#
|
||||
# Flags ct/*.sh update_script blocks that mutate config/data destructively
|
||||
# without calling create_backup. Used in CI / local review before merge.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
CT_DIR="${ROOT}/ct"
|
||||
FAIL=0
|
||||
CHECKED=0
|
||||
FLAGGED=0
|
||||
|
||||
check_file() {
|
||||
local file="$1"
|
||||
local base content block
|
||||
base="$(basename "$file")"
|
||||
content="$(<"$file")"
|
||||
[[ "$content" == *"function update_script"* ]] || return 0
|
||||
CHECKED=$((CHECKED + 1))
|
||||
|
||||
block="$(python3 - "$file" <<'PY'
|
||||
import re, sys
|
||||
text = open(sys.argv[1]).read()
|
||||
m = re.search(r'function update_script\(\).*?(?=^function |\Z)', text, re.S | re.M)
|
||||
print(m.group() if m else "")
|
||||
PY
|
||||
)"
|
||||
|
||||
[[ -n "$block" ]] || return 0
|
||||
[[ "$block" == *"create_backup"* ]] && return 0
|
||||
|
||||
if echo "$block" | grep -qE 'sed -i|\.env|settings\.(py|json)|config\.(json|yml|yaml)|/etc/[^ ]+\.(conf|env)'; then
|
||||
if echo "$block" | grep -qE 'rm -rf|find .* -delete|mv .*\.(bak|old)'; then
|
||||
echo "MISSING create_backup: ct/${base}"
|
||||
FLAGGED=$((FLAGGED + 1))
|
||||
FAIL=1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
for f in "$CT_DIR"/*.sh; do
|
||||
[[ -f "$f" ]] || continue
|
||||
check_file "$f"
|
||||
done
|
||||
|
||||
echo "Checked ${CHECKED} update scripts, flagged ${FLAGGED} without create_backup"
|
||||
exit "$FAIL"
|
||||
Reference in New Issue
Block a user