This commit is contained in:
Brian Zalewski 2024-01-02 00:50:02 +00:00
parent dde63cc16a
commit 5dd6332389

View file

@ -131,45 +131,49 @@ upgradeDarwin() {
fi fi
### Run upgrade process ### Run upgrade process
logg info 'Listing available OS upgrades' && softwareupdate -l HEY="$(softwareupdate -l)"
logg info 'Applying OS upgrades (if available)' logg info 'Listing available OS upgrades'
logg info 'This may take awhile..' UPDATE_CHECK="$(softwareupdate -l)"
expect -c "set timeout -1 if [ "$UPDATE_CHECK" != "No new software available." ]; then
spawn sudo softwareupdate -i -a --agree-to-license logg info 'Applying OS upgrades (if available). This may take awhile..'
expect \"Password:\" expect -c "set timeout -1
send \"${SUDO_PASSWORD}\r\" spawn sudo softwareupdate -i -a --agree-to-license
expect eof" &> /dev/null || EXIT_CODE=$? expect \"Password:\"
if [ -n "$EXIT_CODE" ]; then send \"${SUDO_PASSWORD}\r\"
logg warn 'Error running softwareupdate' expect eof" &> /dev/null || EXIT_CODE=$?
unset EXIT_CODE if [ -n "$EXIT_CODE" ]; then
fi logg warn 'Error running softwareupdate'
# sudo sh -c "sudo softwareupdate -i -a --agree-to-license" || logg error 'Failed to trigger a system update via sudo softwareupdate -i -a --agree-to-license' unset EXIT_CODE
### Reboot if necessary
# Source: https://community.jamf.com/t5/jamf-pro/determine-if-update-requires-restart/m-p/11682
logg info 'Checking if softwareupdate requires a reboot'
if softwareupdate -l | grep restart > /dev/null; then
### Add kickstart script to .zshrc so it triggers automatically
if [ ! -f "$HOME/.zshrc" ] || ! cat "$HOME/.zshrc" | grep '# TEMPORARY FOR INSTALL DOCTOR MACOS' > /dev/null; then
logg info 'Adding kickstart script to ~/.zshrc so script continues automatically if reboot is necessary'
echo 'bash <(curl -sSL --compressed https://install.doctor/start) # TEMPORARY FOR INSTALL DOCTOR MACOS' >> "$HOME/.zshrc"
fi fi
# sudo sh -c "sudo softwareupdate -i -a --agree-to-license" || logg error 'Failed to trigger a system update via sudo softwareupdate -i -a --agree-to-license'
if [ -n "$SUDO_PASSWORD" ] && [ "$SUDO_PASSWORD" != "" ]; then ### Reboot if necessary
### Install kcpassword # Source: https://community.jamf.com/t5/jamf-pro/determine-if-update-requires-restart/m-p/11682
if ! command -v enable_autologin > /dev/null; then logg info 'Checking if softwareupdate requires a reboot'
logg info 'enable_autologin is not installed and it is a requirement for auto-logging in after reboot' && brew install xfreebird/utils/kcpassword if softwareupdate -l | grep restart > /dev/null; then
### Add kickstart script to .zshrc so it triggers automatically
if [ ! -f "$HOME/.zshrc" ] || ! cat "$HOME/.zshrc" | grep '# TEMPORARY FOR INSTALL DOCTOR MACOS' > /dev/null; then
logg info 'Adding kickstart script to ~/.zshrc so script continues automatically if reboot is necessary'
echo 'bash <(curl -sSL --compressed https://install.doctor/start) # TEMPORARY FOR INSTALL DOCTOR MACOS' >> "$HOME/.zshrc"
fi fi
### Enable auto-login via kcpassword if [ -n "$SUDO_PASSWORD" ] && [ "$SUDO_PASSWORD" != "" ]; then
logg info "Enabling autologin for $USER with acquired sudo password" && sudo enable_autologin "$USER" "$SUDO_PASSWORD" ### Install kcpassword
fi if ! command -v enable_autologin > /dev/null; then
logg info 'enable_autologin is not installed and it is a requirement for auto-logging in after reboot' && brew install xfreebird/utils/kcpassword
fi
### Reboot ### Enable auto-login via kcpassword
logg info 'Reboot required' && exit 140 logg info "Enabling autologin for $USER with acquired sudo password" && sudo enable_autologin "$USER" "$SUDO_PASSWORD"
else fi
logg info 'No reboot required for softwareupdate'
### Reboot
logg info 'Reboot required' && exit 140
else
logg info 'No reboot required for softwareupdate'
fi
fi fi
if [ -f "$HOME/.zshrc" ]; then if [ -f "$HOME/.zshrc" ]; then
logg info 'Ensuring provision kickstart script is removed from ~/.zshrc' logg info 'Ensuring provision kickstart script is removed from ~/.zshrc'
if command -v gsed > /dev/null; then if command -v gsed > /dev/null; then