From 948eeb0e3daaf932a5f2404359c7a5e184d1f329 Mon Sep 17 00:00:00 2001 From: Brian Zalewski <59970525+ProfessorManhattan@users.noreply.github.com> Date: Mon, 25 Dec 2023 00:59:44 +0000 Subject: [PATCH] Latest --- .../universal/run_before_01-prepare.sh.tmpl | 2 ++ .../universal/run_before_02-homebrew.sh.tmpl | 12 ++++----- scripts/provision.sh | 25 +++++++++++++------ scripts/src/provision.sh.tmpl | 25 +++++++++++++------ 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/home/.chezmoiscripts/universal/run_before_01-prepare.sh.tmpl b/home/.chezmoiscripts/universal/run_before_01-prepare.sh.tmpl index d2c6d63c..90424592 100644 --- a/home/.chezmoiscripts/universal/run_before_01-prepare.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_before_01-prepare.sh.tmpl @@ -5,6 +5,8 @@ # This script installs required system packages. Each system's required packages are defined in `home/.chezmoitemplates/$DISTRO_ID`, # where `$DISTRO_ID` is equal to the Linux distribution ID found in `/etc/os-release`. +exit 140 + # @description # This script pipes environment variables and a logger function to a temporary file that is included by other scripts. # It is included as a temporary external file to aid in debugging since if the included files were inlined in scripts diff --git a/home/.chezmoiscripts/universal/run_before_02-homebrew.sh.tmpl b/home/.chezmoiscripts/universal/run_before_02-homebrew.sh.tmpl index 9689fd03..2f769639 100644 --- a/home/.chezmoiscripts/universal/run_before_02-homebrew.sh.tmpl +++ b/home/.chezmoiscripts/universal/run_before_02-homebrew.sh.tmpl @@ -164,13 +164,11 @@ upgradeDarwin() { fi ### Reboot - logg info 'Reboot required' - logg info 'Attempting to restart gracefully' - gtimeout 60 osascript -e 'tell application "Finder" to shut down' || OSASCRIPT_EXIT_CODE=$? - if [ -n "$OSASCRIPT_EXIT_CODE" ]; then - logg info 'Reboot required and failed to gracefully shutdown within 1 minute, so forcing reboot' && sudo sh -c 'shutdown -r now' - fi - exit 0 + logg info 'Reboot required' && exit 140 + # gtimeout 60 osascript -e 'tell application "Finder" to shut down' || OSASCRIPT_EXIT_CODE=$? + # if [ -n "$OSASCRIPT_EXIT_CODE" ]; then + # logg info 'Reboot required and failed to gracefully shutdown within 1 minute, so forcing reboot' && sudo sh -c 'shutdown -r now' + # fi else logg info 'No reboot required for softwareupdate' fi diff --git a/scripts/provision.sh b/scripts/provision.sh index 6b53d4f4..a89e4997 100644 --- a/scripts/provision.sh +++ b/scripts/provision.sh @@ -563,33 +563,42 @@ runChezmoi() { logg info 'Running chezmoi apply forcefully' if command -v unbuffer > /dev/null; then if command -v caffeinate > /dev/null; then - caffeinate unbuffer -p chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" + caffeinate unbuffer -p chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? else - unbuffer -p chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" + unbuffer -p chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? fi else if command -v caffeinate > /dev/null; then - caffeinate chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" + caffeinate chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? else - chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" + chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? fi fi else logg info 'Running chezmoi apply' if command -v unbuffer > /dev/null; then if command -v caffeinate > /dev/null; then - caffeinate unbuffer -p chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" + caffeinate unbuffer -p chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? else - unbuffer -p chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" + unbuffer -p chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? fi else if command -v caffeinate > /dev/null; then - caffeinate chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" + caffeinate chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? else - chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" + chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? fi fi fi + if [ -n "$CHEZMOI_EXIT_CODE" ]; then + if [ "$CHEZMOI_EXIT_CODE" = "140" ]; then + logg info "Chezmoi signalled that a reboot is necessary to apply a system update" + logg info "Running softwareupdate with the reboot flag" + sudo softwareupdate -i -a -R --agree-to-license && exit + else + logg error "Chezmoi encountered an error and exitted with an exit code of $CHEZMOI_EXIT_CODE" + fi + fi } # @section Post-provision logic diff --git a/scripts/src/provision.sh.tmpl b/scripts/src/provision.sh.tmpl index 7157fee1..6c221f5d 100644 --- a/scripts/src/provision.sh.tmpl +++ b/scripts/src/provision.sh.tmpl @@ -326,33 +326,42 @@ runChezmoi() { logg info 'Running chezmoi apply forcefully' if command -v unbuffer > /dev/null; then if command -v caffeinate > /dev/null; then - caffeinate unbuffer -p chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" + caffeinate unbuffer -p chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? else - unbuffer -p chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" + unbuffer -p chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? fi else if command -v caffeinate > /dev/null; then - caffeinate chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" + caffeinate chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? else - chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" + chezmoi apply $DEBUG_MODIFIER -k --force 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? fi fi else logg info 'Running chezmoi apply' if command -v unbuffer > /dev/null; then if command -v caffeinate > /dev/null; then - caffeinate unbuffer -p chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" + caffeinate unbuffer -p chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? else - unbuffer -p chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" + unbuffer -p chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? fi else if command -v caffeinate > /dev/null; then - caffeinate chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" + caffeinate chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? else - chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" + chezmoi apply $DEBUG_MODIFIER -k 2>&1 | tee "$LOG_FILE" || CHEZMOI_EXIT_CODE=$? fi fi fi + if [ -n "$CHEZMOI_EXIT_CODE" ]; then + if [ "$CHEZMOI_EXIT_CODE" = "140" ]; then + logg info "Chezmoi signalled that a reboot is necessary to apply a system update" + logg info "Running softwareupdate with the reboot flag" + sudo softwareupdate -i -a -R --agree-to-license && exit + else + logg error "Chezmoi encountered an error and exitted with an exit code of $CHEZMOI_EXIT_CODE" + fi + fi } # @section Post-provision logic