Bash Script to Auto-Update (and reboot) all Updates to Mavericks & Yosemite? I'm seeking a script that I can execute on a newly installed Mavericks or Yosemite computer, that will install all updates, rebooting as necessary and starting again automatically.

For instance, I'd like to:

sudo curl https://gist.githubusercontent.com/ChristopherA/0ddc4c27f8ec7d5a0aed/raw/2e694c616c728593c2af155d18aeeff68b25a222/gistfile1.txt | sh


This then goes to my gist, sends the content to my shell, then is the following script (which currently exists in my gists):

#!/bin/bash

# Installs all system updates, reboot and does it again if necessary.

# Execute on a new mac via:

# sudo curl https://gist.githubusercontent.com/ChristopherA/0ddc4c27f8ec7d5a0aed/raw/2e694c616c728593c2af155d18aeeff68b25a222/gistfile1.txt | sh

# Initially, based on https://jamfnation.jamfsoftware.com/discussion.html?id=7827 which works on 10.8 and untested on 10.9 or 10.10

SWUL=`/usr/sbin/softwareupdate -l | /usr/bin/awk '{printf "%s", $0}'`
SWULER=`/usr/sbin/softwareupdate -l 2&gt;&amp;1 | /usr/bin/head -1`
NoRestartUpdates=`/usr/sbin/softwareupdate -l | /usr/bin/grep -v restart | /usr/bin/grep -B1 recommended | /usr/bin/grep -v recommended | /usr/bin/awk '{print $2}' | /usr/bin/awk '{printf "%s ", $0}'`
osvers=`sw_vers -productVersion | awk -F. '{print $2}'`

if [[ $osvers -lt 8 ]]; then
/bin/echo "Script only for 10.8+ ONLY"
exit 1
elif [ "$SWULER" == "No new software available." ]; then
/bin/echo "$SWULER"
exit 1
elif [[ "$SWUL" == *"[restart]"* ]]; then
echo "Installing Updates that require Restart"
/usr/bin/sudo /usr/sbin/softwareupdate -d -a
/usr/libexec/PListBuddy -c "Copy CompletedProducts InstallAtLogout" /Library/Updates/index.plist
/usr/bin/touch /var/db/.SoftwareUpdateAtLogout
/bin/chmod og-r /var/db/.SoftwareUpdateAtLogout
/usr/libexec/PListBuddy -c "Add -RootInstallMode STRING YES" /var/db/.SoftwareUpdateOptions
/usr/libexec/PListBuddy -c "Add -SkipConfirm STRING YES" /var/db/.SoftwareUpdateOptions
/bin/chmod og-r /var/db/.SoftwareUpdateOptions
elif [[ "$SWUL" == *"[recommended]"* ]]; then
/bin/echo "Installing Updates that does not require Restart"
/usr/bin/sudo /usr/sbin/softwareupdate -i $NoRestartUpdates
fi

exit 0


```

Unfortunately this script from https://jamfnation.jamfsoftware.com/discussion.html?id=7827 does not work on 10.9 or 10.10. 

The Results:

Installing Updates that require Restart
Software Update Tool
Copyright 2002-2012 Apple Inc.

Finding available software

Downloaded iTunes
Downloaded iTunes
Downloaded OS X Yosemite Developer Preview 8
Downloading Yosemite Recovery Update
Downloaded Yosemite Recovery Update
Done.
Copy: Entry, "CompletedProducts", Does Not Exist
touch: /var/db/.SoftwareUpdateAtLogout: Permission denied
chmod: /var/db/.SoftwareUpdateAtLogout: No such file or directory
File Doesn't Exist, Will Create: /var/db/.SoftwareUpdateOptions
File Doesn't Exist, Will Create: /var/db/.SoftwareUpdateOptions
chmod: /var/db/.SoftwareUpdateOptions: No such file or directory
$


There are some clues in the comments of that post, and also at http://hints.macworld.com/article.php?story=20080916220249270

However, I'm not able to find something that can be just a bash script.


Christopher Allen
how about just

sudo softwareupdate -i -a
sudo reboot


by the way, about the script you posted, try adding sudo in front of commands below:

/usr/bin/touch /var/db/.SoftwareUpdateAtLogout
/bin/chmod og-r /var/db/.SoftwareUpdateAtLogout
/usr/libexec/PListBuddy -c "Add -RootInstallMode STRING YES" /var/db/.SoftwareUpdateOptions
/usr/libexec/PListBuddy -c "Add -SkipConfirm STRING YES" /var/db/.SoftwareUpdateOptions
/bin/chmod og-r /var/db/.SoftwareUpdateOptions