#!/usr/bin/env bash # up2date.sh # Run software update until there are no more updates available. # @author Filipp Lepalaan # @package mtk if [[ $(id -u) != 0 ]]; then echo "$(basename $0) must be run as root" 2>&1 exit 1 fi ME=$0 LOGFILE=/var/log/up2date.log PLIST=/Library/LaunchAgents/com.unflyingobject.mtk.up2date.plist # updates available... if /usr/sbin/softwareupdate -l 2>&1 | grep -q 'found the following new' then if [[ ! -e "${PLIST}" ]]; then cat > "${PLIST}" < RunAtLoad Label com.unflyingobject.mtk.up2date ProgramArguments ${ME} EOT /bin/launchctl load -w "${PLIST}" /usr/bin/logger "$(basename $0) loaded" exit 0 fi # wait for the GUI to come up... # while [[ ! (/bin/ps aux | /usr/bin/grep loginwindow | /usr/bin/grep -qv grep) ]]; do # sleep 5 # done /usr/bin/open "${LOGFILE}" /usr/sbin/softwareupdate -ia > "${LOGFILE}" 2>&1 && /sbin/reboot exit 0 fi # no more updates available /bin/launchctl unload -w "${PLIST}" && rm "${PLIST}" /usr/bin/logger "$(basename $0) finished, script unloaded. Have a nice day." exit 0