From 87e3c7581db6f8214dbc633f18b8c39f5706df6a Mon Sep 17 00:00:00 2001 From: tteckster Date: Sun, 8 Oct 2023 10:06:12 -0400 Subject: [PATCH] Update update-lxcs.sh List containers that require a reboot --- misc/update-lxcs.sh | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/misc/update-lxcs.sh b/misc/update-lxcs.sh index 53fdd42c..1254b454 100644 --- a/misc/update-lxcs.sh +++ b/misc/update-lxcs.sh @@ -36,6 +36,21 @@ while read -r TAG ITEM; do EXCLUDE_MENU+=("$TAG" "$ITEM " "OFF") done < <(pct list | awk 'NR>1') excluded_containers=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "Containers on $NODE" --checklist "\nSelect containers to skip from updates:\n" 16 $((MSG_MAX_LENGTH + 23)) 6 "${EXCLUDE_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit + +function needs_reboot() { + local container=$1 + local os=$(pct config "$container" | awk '/^ostype/ {print $2}') + local reboot_required_file="/var/run/reboot-required.pkgs" + if [ -f "$reboot_required_file" ]; then + if [[ "$os" == "ubuntu" || "$os" == "debian" ]]; then + if pct exec "$container" -- [ -s "$reboot_required_file" ]; then + return 0 + fi + fi + fi + return 1 +} + function update_container() { container=$1 header_info @@ -55,6 +70,8 @@ function update_container() { ubuntu | debian | devuan) pct exec "$container" -- bash -c "apt-get update 2>/dev/null | grep 'packages.*upgraded'; apt list --upgradable && apt-get -y dist-upgrade" ;; esac } + +containers_needing_reboot=() header_info for container in $(pct list | awk '{if(NR>1) print $1}'); do if [[ " ${excluded_containers[@]} " =~ " $container " ]]; then @@ -75,8 +92,18 @@ for container in $(pct list | awk '{if(NR>1) print $1}'); do elif [ "$status" == "status: running" ]; then update_container $container fi + if pct exec "$container" -- [ -e "/var/run/reboot-required" ]; then + containers_needing_reboot+=("$container") + fi fi done wait header_info -echo -e "${GN} Finished, Selected Containers Updated. ${CL} \n" +echo -e "${GN}The process is complete, and the selected containers have been 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 +fi +echo ""