From f586a21e1e263bcd0e30f7a1aeb0f4678de39f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20B=C3=A9dard-Couture?= Date: Wed, 2 Jul 2025 21:17:49 -0400 Subject: [PATCH] Add logic for unattended updates and reboot containers if needed (following user prompt) --- tools/pve/update-apps.sh | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tools/pve/update-apps.sh b/tools/pve/update-apps.sh index 98e5e8ab..43a17bfc 100644 --- a/tools/pve/update-apps.sh +++ b/tools/pve/update-apps.sh @@ -104,6 +104,7 @@ if [ "$UNATTENDED_UPDATE" == "yes" ];then UPDATE_CMD="export PHS_SILENT=1;update;" fi +containers_needing_reboot=() for container in $CHOICE; do echo "Updating container:$container" @@ -113,10 +114,24 @@ for container in $CHOICE; do #CHECK FOR RESOURCES - #pct exec $container -- update - pct exec "$container" -- "$UPDATE_CMD" + os=$(pct config "$container" | awk '/^ostype/ {print $2}') + + #4) Update service, using the update command + case "$os" in + alpine) pct exec "$container" -- ash -c "$UPDATE_CMD" ;; + archlinux) pct exec "$container" -- bash -c "$UPDATE_CMD" ;; + fedora | rocky | centos | alma) pct exec "$container" -- bash -c "$UPDATE_CMD" ;; + ubuntu | debian | devuan) pct exec "$container" -- bash -c "$UPDATE_CMD" ;; + opensuse) pct exec "$container" -- bash -c "$UPDATE_CMD" ;; + esac exit_code=$? + if pct exec "$container" -- [ -e "/var/run/reboot-required" ]; then + # Get the container's hostname and add it to the list + container_hostname=$(pct exec "$container" hostname) + containers_needing_reboot+=("$container ($container_hostname)") + fi + if [ $exit_code -eq 0 ]; then msg_ok "Update completed" elif [ "BACKUP_CHOICE" == "yes" ];then @@ -137,3 +152,22 @@ for container in $CHOICE; do exit 1 fi done + +wait +header_info +echo -e "${GN}The process is complete, and the containers have been successfully updated.${CL}\n" +if [ "${#containers_needing_reboot[@]}" -gt 0 ]; then + echo -e "${RD}The following containers require a reboot:${CL}" + for container_name in "${containers_needing_reboot[@]}"; do + echo "$container_name" + done + echo -ne "${INFO} Do you wish to reboot these containers? " + read -r prompt + if [[ ${prompt,,} =~ ^(yes)$ ]]; then + echo -e "${CROSS}${HOLD} ${YWB}Rebooting containers.${CL}" + for container_name in "${containers_needing_reboot[@]}"; do + container=$(echo $container_name | cut -d " " -f 1) + pct reboot ${container} + done + fi +fi