diff --git a/misc/build.func b/misc/build.func index d6075d4b3..c49b86c2e 100644 --- a/misc/build.func +++ b/misc/build.func @@ -5250,9 +5250,78 @@ create_lxc_container() { # Extract Debian OS minor from template name: debian-13-standard_13.1-1_amd64.tar.zst => "13.1" parse_template_osver() { sed -n 's/.*_\([0-9][0-9]*\(\.[0-9]\+\)\?\)-.*/\1/p' <<<"$1"; } + # Switch to Debian 12 template and retry pct create + # Returns: 0 = success, 1 = failed + fallback_to_debian12() { + local old_template="$TEMPLATE" + msg_info "Searching for Debian 12 template" + + # Find latest Debian 12 template + local deb12_template="" + mapfile -t _deb12_local < <( + pveam list "$TEMPLATE_STORAGE" 2>/dev/null | + awk '$1 ~ /debian-12/ && $1 ~ /-standard_/ {print $1}' | + sed 's|.*/||' | sort -t - -k 2 -V + ) + if [[ ${#_deb12_local[@]} -gt 0 ]]; then + deb12_template="${_deb12_local[-1]}" + else + # Check online + if command -v timeout &>/dev/null; then + timeout 30 pveam update >/dev/null 2>&1 || true + else + pveam update >/dev/null 2>&1 || true + fi + mapfile -t _deb12_online < <( + pveam available -section system 2>/dev/null | + awk '{print $2}' | + grep -E '^debian-12.*-standard_' | + sort -t - -k 2 -V 2>/dev/null || true + ) + [[ ${#_deb12_online[@]} -gt 0 ]] && deb12_template="${_deb12_online[-1]}" + fi + + if [[ -z "$deb12_template" ]]; then + msg_error "No Debian 12 template found." + return 1 + fi + + msg_ok "Found Debian 12 template: $deb12_template" + + # Download if needed + local deb12_path + deb12_path="$(pvesm path "$TEMPLATE_STORAGE:vztmpl/$deb12_template" 2>/dev/null || true)" + [[ -z "$deb12_path" ]] && deb12_path="/var/lib/vz/template/cache/$deb12_template" + + if [[ ! -f "$deb12_path" ]]; then + msg_info "Downloading Debian 12 template" + if ! pveam download "$TEMPLATE_STORAGE" "$deb12_template" >>"${BUILD_LOG:-/dev/null}" 2>&1; then + msg_error "Failed to download Debian 12 template." + return 1 + fi + msg_ok "Template downloaded" + fi + + # Update variables + TEMPLATE="$deb12_template" + TEMPLATE_PATH="$deb12_path" + PCT_OSVERSION="12" + export PCT_OSVERSION + + # Retry pct create + msg_info "Retrying container creation with Debian 12" + if pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS >>"$LOGFILE" 2>&1; then + msg_ok "Container created successfully with Debian 12 (fallback from $old_template)." + return 0 + else + msg_error "Container creation with Debian 12 also failed. See $LOGFILE" + return 1 + fi + } + # Offer upgrade for pve-container/lxc-pve if candidate > installed; optional auto-retry pct create # Returns: - # 0 = no upgrade needed + # 0 = no upgrade needed / container created after upgrade or fallback # 1 = upgraded (and if do_retry=yes and retry succeeded, creation done) # 2 = user declined # 3 = upgrade attempted but failed OR retry failed @@ -5280,7 +5349,43 @@ create_lxc_container() { echo " pve-container: installed=${_pvec_i:-n/a} candidate=${_pvec_c:-n/a}" echo " lxc-pve : installed=${_lxcp_i:-n/a} candidate=${_lxcp_c:-n/a}" echo - read -rp "Do you want to upgrade now? [y/N] " _ans