From 4ce7a414e48f82b434f0ee1402c375d4184320c2 Mon Sep 17 00:00:00 2001 From: Brian Zalewski <59970525+ProfessorManhattan@users.noreply.github.com> Date: Mon, 25 Dec 2023 03:05:09 +0000 Subject: [PATCH] Latest --- scripts/partials/reboot | 35 ++++++++++++++++++----------------- scripts/provision.sh | 35 ++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/scripts/partials/reboot b/scripts/partials/reboot index 85276ff3..febbd519 100644 --- a/scripts/partials/reboot +++ b/scripts/partials/reboot @@ -6,22 +6,23 @@ # After determining whether or not a reboot is required, the script will attempt to automatically # reboot the machine. handleRequiredReboot() { - if [ -d /Applications ] && [ -d /System ]; then - ### macOS - logg info 'Checking if there is a pending update' && defaults read /Library/Updates/index.plist InstallAtLogout - # TODO - Uncomment this when we can determine conditions for reboot - # sudo shutdown -r now - elif [ -f /var/run/reboot-required ]; then - ### Linux - logg info '/var/run/reboot-required is present so a reboot is required' - if command -v systemctl > /dev/null; then - logg info 'systemctl present so rebooting with sudo systemctl start reboot.target' && sudo systemctl start reboot.target - elif command -v reboot > /dev/null; then - logg info 'reboot available as command so rebooting with sudo reboot' && sudo reboot - elif command -v shutdown > /dev/null; then - logg info 'shutdown command available so rebooting with sudo shutdown -r now' && sudo shutdown -r now - else - logg warn 'Reboot required but unable to determine appropriate restart command' - fi + if [ -d /Applications ] && [ -d /System ]; then + ### macOS + if ! defaults read /Library/Updates/index.plist InstallAtLogout 2>&1 | grep 'does not exist' > /dev/null; then + logg info 'There appears to be an update that requires a reboot' + logg info 'Attempting to reboot gracefully' && osascript -e 'tell application "Finder" to shut down' fi + elif [ -f /var/run/reboot-required ]; then + ### Linux + logg info '/var/run/reboot-required is present so a reboot is required' + if command -v systemctl > /dev/null; then + logg info 'systemctl present so rebooting with sudo systemctl start reboot.target' && sudo systemctl start reboot.target + elif command -v reboot > /dev/null; then + logg info 'reboot available as command so rebooting with sudo reboot' && sudo reboot + elif command -v shutdown > /dev/null; then + logg info 'shutdown command available so rebooting with sudo shutdown -r now' && sudo shutdown -r now + else + logg warn 'Reboot required but unable to determine appropriate restart command' + fi + fi } \ No newline at end of file diff --git a/scripts/provision.sh b/scripts/provision.sh index 12b1bc3d..b47c214d 100644 --- a/scripts/provision.sh +++ b/scripts/provision.sh @@ -298,24 +298,25 @@ ensureHomebrew() { # After determining whether or not a reboot is required, the script will attempt to automatically # reboot the machine. handleRequiredReboot() { - if [ -d /Applications ] && [ -d /System ]; then - ### macOS - logg info 'Checking if there is a pending update' && defaults read /Library/Updates/index.plist InstallAtLogout - # TODO - Uncomment this when we can determine conditions for reboot - # sudo shutdown -r now - elif [ -f /var/run/reboot-required ]; then - ### Linux - logg info '/var/run/reboot-required is present so a reboot is required' - if command -v systemctl > /dev/null; then - logg info 'systemctl present so rebooting with sudo systemctl start reboot.target' && sudo systemctl start reboot.target - elif command -v reboot > /dev/null; then - logg info 'reboot available as command so rebooting with sudo reboot' && sudo reboot - elif command -v shutdown > /dev/null; then - logg info 'shutdown command available so rebooting with sudo shutdown -r now' && sudo shutdown -r now - else - logg warn 'Reboot required but unable to determine appropriate restart command' - fi + if [ -d /Applications ] && [ -d /System ]; then + ### macOS + if ! defaults read /Library/Updates/index.plist InstallAtLogout 2>&1 | grep 'does not exist' > /dev/null; then + logg info 'There appears to be an update that requires a reboot' + logg info 'Attempting to reboot gracefully' && osascript -e 'tell application "Finder" to shut down' fi + elif [ -f /var/run/reboot-required ]; then + ### Linux + logg info '/var/run/reboot-required is present so a reboot is required' + if command -v systemctl > /dev/null; then + logg info 'systemctl present so rebooting with sudo systemctl start reboot.target' && sudo systemctl start reboot.target + elif command -v reboot > /dev/null; then + logg info 'reboot available as command so rebooting with sudo reboot' && sudo reboot + elif command -v shutdown > /dev/null; then + logg info 'shutdown command available so rebooting with sudo shutdown -r now' && sudo shutdown -r now + else + logg warn 'Reboot required but unable to determine appropriate restart command' + fi + fi } # @description Load default settings if it is in a CI setting setCIEnvironmentVariables() {