This commit is contained in:
Brian Zalewski 2023-12-25 00:59:44 +00:00
parent 7d541c9798
commit 948eeb0e3d
4 changed files with 41 additions and 23 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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