Files
ProxMenux/scripts/utilities/proxmox_update.sh

150 lines
4.8 KiB
Bash
Raw Normal View History

2025-07-01 20:49:36 +02:00
#!/bin/bash
2025-07-04 21:44:19 +02:00
# ==========================================================
2026-05-09 18:59:59 +02:00
# ProxMenux - Proxmox System Update
2025-07-04 21:44:19 +02:00
# ==========================================================
# Author : MacRimi
# Copyright : (c) 2024 MacRimi
2026-05-09 18:59:59 +02:00
# License : GPL-3.0
# https://github.com/MacRimi/ProxMenux/blob/main/LICENSE
2025-07-04 21:44:19 +02:00
# Version : 1.0
# ==========================================================
# Description:
2026-05-09 18:59:59 +02:00
# Wrapper that detects the running Proxmox major version and
# delegates to the matching worker script:
# - PVE 8 -> scripts/global/update-pve8.sh
# - PVE 9 -> scripts/global/update-pve9_2.sh
# After the worker finishes, runs the post-update cleanup
# (apt-get autoremove + autoclean) and prompts for an immediate
# reboot if the kernel was updated or /var/run/reboot-required
# was created.
2025-07-04 21:44:19 +02:00
#
2026-05-09 18:59:59 +02:00
# Features (delegated to worker scripts):
# - APT repository hygiene (Proxmox + Debian)
# - Removal of duplicate / conflicting sources
# - Switch to the no-subscription Proxmox repository
# - Full apt update + dist-upgrade
# - Installs essential packages if missing (zfsutils, chrony, ...)
# - LVM / storage sanity checks and header repair
# - Removes conflicting time-sync packages
# - Post-update system cleanup
# - Reboot prompt when kernel changed
# ==========================================================
2025-07-04 21:44:19 +02:00
#
# The goal of this script is to simplify and secure the update process for Proxmox,
# reduce manual intervention, and prevent common repository and package errors.
# ==========================================================
2025-07-01 20:49:36 +02:00
BASE_DIR="/usr/local/share/proxmenux"
UTILS_FILE="$BASE_DIR/utils.sh"
VENV_PATH="/opt/googletrans-env"
if [[ -f "$UTILS_FILE" ]]; then
source "$UTILS_FILE"
fi
load_language
initialize_cache
2025-10-31 20:03:34 +01:00
export SCRIPT_TITLE="Proxmox system update"
2025-07-01 20:49:36 +02:00
# ==========================================================
2025-08-07 15:45:46 +02:00
NECESSARY_REBOOT=1
2025-07-01 20:49:36 +02:00
apt_upgrade() {
2026-05-09 18:59:59 +02:00
local pve_version pve_raw
# Capture both stdout and the rc so a failure is visible in the
# error message — silent `2>/dev/null` previously hid the real cause
# (binary missing / output malformed). Audit Tier 6 — `proxmox_update.sh`
# detección de versión silenciosa.
pve_raw=$(pveversion 2>&1)
local pve_rc=$?
pve_version=$(echo "$pve_raw" | grep -oP 'pve-manager/\K[0-9]+' | head -1)
2025-07-04 21:44:19 +02:00
2025-08-07 15:45:46 +02:00
if [[ -z "$pve_version" ]]; then
2026-05-09 18:59:59 +02:00
if (( pve_rc != 0 )); then
msg_error "Unable to detect Proxmox version (pveversion exit $pve_rc): ${pve_raw:0:200}"
else
msg_error "Unable to parse Proxmox version from output: ${pve_raw:0:200}"
fi
2025-07-01 20:49:36 +02:00
return 1
fi
2025-08-07 15:45:46 +02:00
if [[ "$pve_version" -ge 9 ]]; then
show_proxmenux_logo
2025-10-31 20:09:52 +01:00
msg_title "$(translate "$SCRIPT_TITLE")"
bash "$LOCAL_SCRIPTS/global/update-pve9_2.sh"
2025-07-01 20:49:36 +02:00
2025-08-07 18:08:37 +02:00
else
2025-08-07 15:45:46 +02:00
show_proxmenux_logo
2025-10-31 20:16:42 +01:00
msg_title "$(translate "Proxmox system update")"
bash "$LOCAL_SCRIPTS/global/update-pve8.sh"
2025-08-07 18:08:37 +02:00
2025-07-01 20:49:36 +02:00
fi
2025-08-07 15:45:46 +02:00
}
2025-08-07 15:49:22 +02:00
2025-08-07 18:08:37 +02:00
check_reboot() {
NECESSARY_REBOOT=0
if [ -f /var/run/reboot-required ]; then
NECESSARY_REBOOT=1
fi
if grep -q "linux-image" "$log_file" 2>/dev/null; then
NECESSARY_REBOOT=1
fi
2025-07-01 20:49:36 +02:00
if [[ "$NECESSARY_REBOOT" -eq 1 ]]; then
2025-08-07 18:08:37 +02:00
if whiptail --title "$(translate "Reboot Required")" \
--yesno "$(translate "Some changes require a reboot to take effect. Do you want to restart now?")" 10 60; then
msg_info "$(translate "Removing no longer required packages and purging old cached updates...")"
apt-get -y autoremove >/dev/null 2>&1
apt-get -y autoclean >/dev/null 2>&1
msg_ok "$(translate "Cleanup finished")"
echo -e
msg_success "$(translate "Press Enter to continue...")"
read -r
msg_warn "$(translate "Rebooting the system...")"
reboot
2025-07-01 20:49:36 +02:00
else
2025-08-07 18:08:37 +02:00
msg_info "$(translate "Removing no longer required packages and purging old cached updates...")"
apt-get -y autoremove >/dev/null 2>&1
apt-get -y autoclean >/dev/null 2>&1
msg_ok "$(translate "Cleanup finished")"
echo -e
msg_info2 "$(translate "You can reboot later manually.")"
echo -e
msg_success "$(translate "Press Enter to continue...")"
read -r
return 0
2025-07-01 20:49:36 +02:00
fi
else
msg_info "$(translate "Removing no longer required packages and purging old cached updates...")"
apt-get -y autoremove >/dev/null 2>&1
apt-get -y autoclean >/dev/null 2>&1
msg_ok "$(translate "Cleanup finished")"
2025-08-07 18:11:32 +02:00
echo -e
2025-08-07 18:08:37 +02:00
msg_ok "$(translate "All changes applied. No reboot required.")"
echo -e
2025-07-01 20:49:36 +02:00
msg_success "$(translate "Press Enter to return to menu...")"
read -r
fi
2025-08-07 18:08:37 +02:00
}
apt_upgrade
check_reboot
2025-07-01 20:49:36 +02:00
2025-08-07 18:08:37 +02:00
2025-07-01 20:49:36 +02:00
2025-08-07 15:49:22 +02:00