Currently, I’m trying to “bullet proof” (eliminate most potential pitfalls) my script. I’ve added to my script the ability to detect network connectivity (no point in doing online updates if your not online). If it is not found, it will bring up the various network interfaces.
##############################################################################
## This work is licensed under the Creative Commons Attribution-Share Alike ##
## 3.0 United States License. To view a copy of this license, visit ##
## http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to ##
## Creative Commons, 171 Second Street, Suite 300, San Francisco, ##
## California, 94105, USA. ##
## ##
## risoUpdate.sh Copyright Paul R. Adams, 2007 ##
##############################################################################
#!/bin/bash
#-- First, replace the current updates.log file with the date. Second,
# ask for the administrative password (which is required for software
# updates and the potential reboot). Third, export an environmental
# variable that elminiates any pesky dialog boxes. Fourth, activate
# scheduled downloads and append any output (stout and sterr) to the
# the updates.log file. Finally, start OS X version specific code bits. --#
date > /tmp/updates.log 2>&1 ;
read -p “Please enter the administration password: “ Password
export COMMAND_LINE_INSTALL=1 ;
softwareupdate --schedule on >> /tmp/updates.log 2>&1 ;
if [ “$(sw_vers -productVersion | cut -c 1-4)” == “10.4” ] ;
# -- If OS is 10.4, reset ignored updates. -- #
then softwareupdate --reset-ignored >> /tmp/updates.log 2>&1 ;
# -- If OS is 10.3, reset ignored updates. -- #
else softwareupdate --ignored remove -a >> /tmp/updates.log 2>&1 ;
fi
# -- Do the various network interfaces have IP addresses -- #
if [ -z “$(ifconfig en0 | grep inet)” ] ;
then en0_up=”no” ;
else en0_up=”yes” ;
fi
if [ -z “$(ifconfig en1 | grep inet)” ] ;
then en1_up=”no” ;
else en1_up=”yes” ;
fi
if [ -z “$ifconfig en2 | grep inet)” ] ;
then en2_up=”no” ;
else en2_up=”yes” ;
fi
# -- If none of the network interfaces have an IP address, bring up the
# network interfaces and acquire an IP address. -- #
if (( en0_up==no && en1_up==no && en2_up=no )) ;
then echo $Password | sudo -S ifconfig en0 up >> /tmp/updates.log 2>&1 ;
echo $Password | sudo -S ifconfig en1 up >> /tmp/updates.log 2>&1 ;
echo $Password | sudo -S ifconfig en2 up >> /tmp/updates.log 2>&1 ;
fi
sleep 15 ;
#-- Install all available updates and append any output to updates.log. Next,
# update the “prebinding” information for OS X (optimizing step). Finally,
# reboot if grep finds “restart” in the updates.log file. -- #
echo $Password | sudo -S softwareupdate -i -a >> /tmp/updates.log 2>&1 ;
echo $Password | sudo -S update_prebinding -root / -force ;
cat /tmp/updates.log | grep restart && echo $Password | sudo -S reboot ;