#!/usr/local/bin/ksh # # LICENCE: # Copyright (C) 2005 Andrew Wellington. # All rights reserved. # # Redistribution and use in source and binary forms, with or # without modification, are permitted provided that the following # conditions are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # README: # A script to download and mirror the Apple Software Updates # available for Mac OS X (10.4 "Tiger"), in conjunction with # Andrew Wellington's SUEnabler application, which allows an # administrator to set a different download location for the # update catalog and update packages. # # This script requires GNU wget, and requires the following # directory structure to operate (feel free to rename the # LOCALDIR and /sumirror/files/ paths below according to # your requirements: # # sumirror/ # |-- content # | |-- files # | | |-- [ All the various updater ] # | | `-- [ files supplied by Apple ] # | |-- index.sucatalog # | |-- sumirror.curlist # | |-- sumirror.newlist # | |-- sumirror.sucatalog # | `-- sumirror.urllist # `-- sumirror # # If you have wget and have simply untarred this directory, you # should be able to run this software by typing ./sumirror # # It is assumed you'll be running a webserver (eg Apache) on the # server you're running this on. Simply make a symlink to the # content directory as follows: # # cd /path/to/webroot/ # ln -s /path/to/sumirror/content sumirror # # Then, open up your copy of Software Update Enabler and enter # your the following into it: # # http://www.your-web-server/sumirror/ # # You should then run the sumirror script periodically using # cron or launchd. If you've read this far, I'll assume you # already know how to use these utilities and don't need help # from me. # # OBLIGATORY PLUG: # Software Update Enabler can be downloaded here: # # http://www.wiretapped.net/~proton/suenabler/index.html SUMASTER="http://swscan.apple.com/content/catalogs/index-1.sucatalog" SUMASTERHOST="swcdn.apple.com" LOCALDIR="./content" GREP="`which grep`" SED="`which sed`" TR="`which tr`" WGET="`which wget`" XARGS="`which xargs`" # Download Apple's catalog file to our working directory echo "*** Downloading Software Updates Catalog..." $WGET -N -q -O $LOCALDIR/sumirror.sucatalog $SUMASTER # Strip it back to just the URLs of the files we need to mirror $GREP $SUMASTERHOST $LOCALDIR/sumirror.sucatalog | tr -d "\t" | $SED 's/\//g;s/\<\/string\>//g' > $LOCALDIR/sumirror.urllist # Jump into the directory we want the files actually stored and download them using wget echo "*** Mirroring Software Update Packages..." cd $LOCALDIR/files $WGET -N -q -i ../sumirror.urllist cd ../.. # Now, prepare an index.sucatalog file for the Software Update.app to download and refer to, # but now, instead of URLs at Apple's download site, replace them with our own (modify this # to suit your requirements). echo "*** Running Post-Mirroring Scripts..." $SED 's|http://swcdn.*/\(.*\)|http://www.wiretapped.net/sumirror/files/\1|g' < $LOCALDIR/sumirror.sucatalog > $LOCALDIR/index.sucatalog # Apple may pull some updates if problems with them are discovered. We therefore need to check # that no old files are present in the main download directory. Prepare a sorted list of the # filenames Apple is telling us we should have, then prepare a list of what's actually there. # Compare them, then delete any that aren't on the new list. echo "*** Optimising Content Directories..." $SED 's|http://swcdn.*/\(.*\)|\1|g' < $LOCALDIR/sumirror.urllist | sort > $LOCALDIR/sumirror.newlist ls $LOCALDIR/files | xargs -n1 | sort > $LOCALDIR/sumirror.curlist cd $LOCALDIR/files $GREP -F -v -f ../sumirror.newlist ../sumirror.curlist | $XARGS -n 1 rm -f echo "*** Done!"