Skip to content

Instantly share code, notes, and snippets.

@x56
Created March 19, 2016 04:53
Show Gist options
  • Save x56/7790380ea7a8980c69c3 to your computer and use it in GitHub Desktop.
Save x56/7790380ea7a8980c69c3 to your computer and use it in GitHub Desktop.
Script for downloading all available AirPort device firmwares
#!/usr/bin/env python
import errno
import os
import plistlib
import sys
import urllib
def makedirs_if_absent(path):
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
#XXX: not really doing much to check the invocation yet
if len(sys.argv) != 2:
print "Usage: grab_firmwares.py [destination path]"
sys.exit(1)
# start out with the version plist
#TODO: should also grab version.xml.signature and verify our copy of the plist
(version_file, junk) = urllib.urlretrieve("http://apsu.apple.com/version.xml")
version_plist = plistlib.readPlist(version_file)
# available keys are "AirPortUtility", "AirPortUtilityWin", and "firmwareUpdates"
# we only care about the last one right now
for fw_dict in version_plist["firmwareUpdates"]:
fw_productid = fw_dict["productID"]
fw_url = fw_dict["location"]
fw_filename = fw_url.rsplit("/", 1)[1]
fw_dir = os.path.join(sys.argv[1], fw_productid)
makedirs_if_absent(fw_dir)
fw_path = os.path.join(fw_dir, fw_filename)
print "Downloading {0}".format(fw_url)
urllib.urlretrieve(fw_url, fw_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment