├── .gitignore ├── README.md └── adc_download.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | adc-download 2 | ============ 3 | 4 | A script to perform resumable downloads from the Apple Developer Center 5 | 6 | Safari's resume facility is just awful -- it'll randomly restart downloads from the beginning, clobbering anything that's already been downloaded, and the resume button will frequently disappear entirely and mysteriously from the downloads window. And if the session has expired, it'll cause all kinds of havoc. 7 | 8 | Anyone downloading the gazillion-gb iOS/Mac SDK + XCode on a slow and/or expensive connection will know the sheer fisticuffs-inspiring irritation this creates -- speaking personally, living on a mobile broadband connection that's usually changed at £3 per gig and often runs about as fast as I could send the data via carrier pigeon, this usually makes me want to storm Cupertino with a pitchfork. 9 | 10 | Thus, this script. 11 | 12 | It'll ask for your Apple ID and password, and store it in the keychain for you, and it'll resume from the current working directory. 13 | 14 | Chuck it somewhere like `/usr/local/bin`, make sure it's executable (`chmod +x /usr/local/bin/adc_download.sh`) and call it from Terminal like: 15 | 16 | `adc_download.sh https://developer.apple.com/devcenter/download.action?path=/Developer_Tools/xcode_4_gm_seed/xcode_4_gm_seed_.dmg` 17 | 18 | If you've already started the download in Safari, just grab the partially-downloaded file from within the *.download* package Safari creates. 19 | 20 | [Resuming ADC downloads (‘cos Safari sucks)](http://atastypixel.com/blog/resuming-adc-downloads-cos-safari-sucks/) -------------------------------------------------------------------------------- /adc_download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ADC downloader tool 3 | # 4 | # Usage: 5 | # adc_download.sh [download URL] 6 | # 7 | # Michael Tyson, A Tasty Pixel 8 | # 9 | # Multi-team support via Christopher Bowns (@cbowns, http://cbowns.com/) 10 | 11 | 12 | # Fill in the following with team ID when you view source on . 13 | # Team names are on the lines below 'select name="memberDisplayId" id="teams"' 14 | # Use formfind at to reveal the form contents if you need help. 15 | myaccountID="" 16 | teamloginURL="https://developer.apple.com/devcenter/saveTeamSelection.action" 17 | 18 | if [ ! "$1" ]; then 19 | echo "Usage:" 20 | echo " $0 [ADC Download URL]" 21 | exit 1 22 | fi; 23 | 24 | downloadURL=`echo "$1" | sed -E 's@http://adcdownload.apple.com|https://developer.apple.com/(iphone|ios)/download.action\?path=@https://developer.apple.com/devcenter/download.action?path=@'` 25 | 26 | if grep -q myacinfo /tmp/adccookies.txt 2>/dev/null; then 27 | echo "Starting download..." 28 | status=`curl -L -O -C - -b /tmp/adccookies.txt "$downloadURL" --write-out '%{http_code}'` 29 | rc=$? 30 | if [ $rc = "33" ]; then 31 | rm /tmp/adccookies.txt 32 | echo "Session expired." 33 | elif [ $rc != "0" ]; then 34 | if [ "$status" != "403" ]; then 35 | echo "Unexpected error $status (return code $rc)" 36 | exit 1 37 | fi 38 | 39 | echo "Not logged in" 40 | else 41 | echo "Complete" 42 | exit 0 43 | fi 44 | fi 45 | 46 | echo "Preparing to login to ADC..." 47 | 48 | authinfo=`security find-internet-password -s daw.apple.com -g 2>&1` 49 | [[ $authinfo =~ \"acct\"\=\"([^\"]+)\" ]] && acct="${BASH_REMATCH[1]}" 50 | [[ $authinfo =~ password:\ \"([^\"]+)\" ]] && pass="${BASH_REMATCH[1]}" 51 | if [ ! "$acct" -o ! "$pass" ]; then 52 | read -p "ADC Username: " acct 53 | read -s -p "Password: " pass 54 | echo '' 55 | if [ ! "$acct" -o ! "$pass" ]; then 56 | exit 1; 57 | fi 58 | newlogin=1 59 | fi 60 | 61 | echo 'Logging in...' 62 | 63 | loginpage=`curl -s -L "$downloadURL"` 64 | [[ $loginpage =~ form[^\>]+action=\"([^\"]+)\" ]] && loginurl="https://daw.apple.com/${BASH_REMATCH[1]}" 65 | [[ $loginpage =~ name=\"wosid\"\ value=\"([^\"]+)\" ]] && wosid="${BASH_REMATCH[1]}" 66 | 67 | if [ ! "$loginurl" ]; then 68 | echo "Unexpected response" 69 | exit 1 70 | fi; 71 | 72 | curl -s -c /tmp/adccookies.txt -L -F theAccountName="$acct" -F theAccountPW="$pass" -F 1.Continue=1 -F theAuxValue= -F wosid="$wosid" "$loginurl" -o /dev/null 73 | if ! grep -q myacinfo /tmp/adccookies.txt 2>/dev/null; then 74 | echo "Login failed" 75 | exit 1 76 | fi 77 | 78 | if [ "$newlogin" ]; then 79 | security add-internet-password -U -a "$acct" -s daw.apple.com -w "$pass" -T "$0" 80 | fi 81 | 82 | if [ "$myaccountID" ]; then 83 | # submit $myaccountID as teams to the saveTeamSelection url 84 | # for some reason, adding -i here makes it all work. 85 | curl -i -s -b /tmp/adccookies.txt -c /tmp/adccookies.txt -F memberDisplayId="$myaccountID" -F "action:saveTeamSelection!save"="Continue" $teamloginURL -o /dev/null 86 | fi 87 | 88 | echo "Starting download..." 89 | status=`curl -L -O -C - -b /tmp/adccookies.txt "$downloadURL" --write-out '%{http_code}'` 90 | if [ $? != "0" ]; then 91 | if [ "$status" != "403" ]; then 92 | echo "Unexpected error $status" 93 | exit 1 94 | fi 95 | 96 | echo "Login failed" 97 | exit 1 98 | else 99 | echo "Complete" 100 | fi --------------------------------------------------------------------------------