Update build.func
This commit is contained in:
parent
8ce34b4ee0
commit
b622505d81
170
misc/build.func
170
misc/build.func
@ -2346,87 +2346,11 @@ destroy_lxc() {
|
||||
fi
|
||||
}
|
||||
|
||||
create_lxc_container() {
|
||||
# ------------------------------------------------------------------------------
|
||||
# Optional verbose mode (debug tracing)
|
||||
# ------------------------------------------------------------------------------
|
||||
if [[ "${CREATE_LXC_VERBOSE:-no}" == "yes" ]]; then set -x; fi
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Helpers (dynamic versioning / template parsing)
|
||||
# ------------------------------------------------------------------------------
|
||||
pkg_ver() { dpkg-query -W -f='${Version}\n' "$1" 2>/dev/null || echo ""; }
|
||||
pkg_cand() { apt-cache policy "$1" 2>/dev/null | awk '/Candidate:/ {print $2}'; }
|
||||
|
||||
ver_ge() { dpkg --compare-versions "$1" ge "$2"; }
|
||||
ver_gt() { dpkg --compare-versions "$1" gt "$2"; }
|
||||
ver_lt() { dpkg --compare-versions "$1" lt "$2"; }
|
||||
|
||||
# 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"; }
|
||||
|
||||
# Offer upgrade for pve-container/lxc-pve if candidate > installed; optional auto-retry pct create
|
||||
# Returns:
|
||||
# 0 = no upgrade needed
|
||||
# 1 = upgraded (and if do_retry=yes and retry succeeded, creation done)
|
||||
# 2 = user declined
|
||||
# 3 = upgrade attempted but failed OR retry failed
|
||||
offer_lxc_stack_upgrade_and_maybe_retry() {
|
||||
local do_retry="${1:-no}" # yes|no
|
||||
local _pvec_i _pvec_c _lxcp_i _lxcp_c need=0
|
||||
|
||||
_pvec_i="$(pkg_ver pve-container)"
|
||||
_lxcp_i="$(pkg_ver lxc-pve)"
|
||||
_pvec_c="$(pkg_cand pve-container)"
|
||||
_lxcp_c="$(pkg_cand lxc-pve)"
|
||||
|
||||
if [[ -n "$_pvec_c" && "$_pvec_c" != "none" ]]; then
|
||||
ver_gt "$_pvec_c" "${_pvec_i:-0}" && need=1
|
||||
fi
|
||||
if [[ -n "$_lxcp_c" && "$_lxcp_c" != "none" ]]; then
|
||||
ver_gt "$_lxcp_c" "${_lxcp_i:-0}" && need=1
|
||||
fi
|
||||
if [[ $need -eq 0 ]]; then
|
||||
msg_debug "No newer candidate for pve-container/lxc-pve (installed=$_pvec_i/$_lxcp_i, cand=$_pvec_c/$_lxcp_c)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "An update for the Proxmox LXC stack is available:"
|
||||
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
|
||||
case "${_ans,,}" in
|
||||
y | yes)
|
||||
msg_info "Upgrading Proxmox LXC stack (pve-container, lxc-pve)"
|
||||
if apt-get update -qq >/dev/null && apt-get install -y --only-upgrade pve-container lxc-pve >/dev/null; then
|
||||
msg_ok "LXC stack upgraded."
|
||||
if [[ "$do_retry" == "yes" ]]; then
|
||||
msg_info "Retrying container creation after upgrade"
|
||||
if pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[@]}" >>"$LOGFILE" 2>&1; then
|
||||
msg_ok "Container created successfully after upgrade."
|
||||
return 1
|
||||
else
|
||||
msg_error "pct create still failed after upgrade. See $LOGFILE"
|
||||
return 3
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
else
|
||||
msg_error "Upgrade failed. Please check APT output."
|
||||
return 3
|
||||
fi
|
||||
;;
|
||||
*) return 2 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Storage discovery / selection helpers
|
||||
# ------------------------------------------------------------------------------
|
||||
# ===== Storage discovery / selection helpers (ported from create_lxc.sh) =====
|
||||
resolve_storage_preselect() {
|
||||
# ------------------------------------------------------------------------------
|
||||
# Storage discovery / selection helpers
|
||||
# ------------------------------------------------------------------------------
|
||||
# ===== Storage discovery / selection helpers (ported from create_lxc.sh) =====
|
||||
resolve_storage_preselect() {
|
||||
local class="$1" preselect="$2" required_content=""
|
||||
case "$class" in
|
||||
template) required_content="vztmpl" ;;
|
||||
@ -2459,9 +2383,9 @@ create_lxc_container() {
|
||||
fi
|
||||
STORAGE_RESULT="$preselect"
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
check_storage_support() {
|
||||
check_storage_support() {
|
||||
local CONTENT="$1" VALID=0
|
||||
while IFS= read -r line; do
|
||||
local STORAGE_NAME
|
||||
@ -2469,9 +2393,9 @@ create_lxc_container() {
|
||||
[[ -n "$STORAGE_NAME" ]] && VALID=1
|
||||
done < <(pvesm status -content "$CONTENT" 2>/dev/null | awk 'NR>1')
|
||||
[[ $VALID -eq 1 ]]
|
||||
}
|
||||
}
|
||||
|
||||
select_storage() {
|
||||
select_storage() {
|
||||
local CLASS=$1 CONTENT CONTENT_LABEL
|
||||
case $CLASS in
|
||||
container)
|
||||
@ -2552,6 +2476,82 @@ create_lxc_container() {
|
||||
done
|
||||
return 0
|
||||
done
|
||||
}
|
||||
|
||||
create_lxc_container() {
|
||||
# ------------------------------------------------------------------------------
|
||||
# Optional verbose mode (debug tracing)
|
||||
# ------------------------------------------------------------------------------
|
||||
if [[ "${CREATE_LXC_VERBOSE:-no}" == "yes" ]]; then set -x; fi
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Helpers (dynamic versioning / template parsing)
|
||||
# ------------------------------------------------------------------------------
|
||||
pkg_ver() { dpkg-query -W -f='${Version}\n' "$1" 2>/dev/null || echo ""; }
|
||||
pkg_cand() { apt-cache policy "$1" 2>/dev/null | awk '/Candidate:/ {print $2}'; }
|
||||
|
||||
ver_ge() { dpkg --compare-versions "$1" ge "$2"; }
|
||||
ver_gt() { dpkg --compare-versions "$1" gt "$2"; }
|
||||
ver_lt() { dpkg --compare-versions "$1" lt "$2"; }
|
||||
|
||||
# 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"; }
|
||||
|
||||
# Offer upgrade for pve-container/lxc-pve if candidate > installed; optional auto-retry pct create
|
||||
# Returns:
|
||||
# 0 = no upgrade needed
|
||||
# 1 = upgraded (and if do_retry=yes and retry succeeded, creation done)
|
||||
# 2 = user declined
|
||||
# 3 = upgrade attempted but failed OR retry failed
|
||||
offer_lxc_stack_upgrade_and_maybe_retry() {
|
||||
local do_retry="${1:-no}" # yes|no
|
||||
local _pvec_i _pvec_c _lxcp_i _lxcp_c need=0
|
||||
|
||||
_pvec_i="$(pkg_ver pve-container)"
|
||||
_lxcp_i="$(pkg_ver lxc-pve)"
|
||||
_pvec_c="$(pkg_cand pve-container)"
|
||||
_lxcp_c="$(pkg_cand lxc-pve)"
|
||||
|
||||
if [[ -n "$_pvec_c" && "$_pvec_c" != "none" ]]; then
|
||||
ver_gt "$_pvec_c" "${_pvec_i:-0}" && need=1
|
||||
fi
|
||||
if [[ -n "$_lxcp_c" && "$_lxcp_c" != "none" ]]; then
|
||||
ver_gt "$_lxcp_c" "${_lxcp_i:-0}" && need=1
|
||||
fi
|
||||
if [[ $need -eq 0 ]]; then
|
||||
msg_debug "No newer candidate for pve-container/lxc-pve (installed=$_pvec_i/$_lxcp_i, cand=$_pvec_c/$_lxcp_c)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "An update for the Proxmox LXC stack is available:"
|
||||
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
|
||||
case "${_ans,,}" in
|
||||
y | yes)
|
||||
msg_info "Upgrading Proxmox LXC stack (pve-container, lxc-pve)"
|
||||
if apt-get update -qq >/dev/null && apt-get install -y --only-upgrade pve-container lxc-pve >/dev/null; then
|
||||
msg_ok "LXC stack upgraded."
|
||||
if [[ "$do_retry" == "yes" ]]; then
|
||||
msg_info "Retrying container creation after upgrade"
|
||||
if pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[@]}" >>"$LOGFILE" 2>&1; then
|
||||
msg_ok "Container created successfully after upgrade."
|
||||
return 1
|
||||
else
|
||||
msg_error "pct create still failed after upgrade. See $LOGFILE"
|
||||
return 3
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
else
|
||||
msg_error "Upgrade failed. Please check APT output."
|
||||
return 3
|
||||
fi
|
||||
;;
|
||||
*) return 2 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user