Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@timiscoding
Created July 19, 2020 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timiscoding/cfaa75fdda131a5b2fe6cc0945041e34 to your computer and use it in GitHub Desktop.
Save timiscoding/cfaa75fdda131a5b2fe6cc0945041e34 to your computer and use it in GitHub Desktop.
download xcode bash script
#!/bin/bash
# This script downloads xcode at a speed of your choice so that you still have usable internet.
# Requires an Apple Developer account.
#
# command to schedule 'script' to run at 'time' using 'at' util
# at <time> -f <script>
getFile () {
# -O use the same filename as the url, -C - resume download from end of partial file, set max 300kbps download rate
params="-O -C - --limit-rate 300k"
# To get the download link for xcode:
# 1. Login to your Apple Developer account and open https://developer.apple.com/download/more/
# 2. find the latest xcode in the table and click '+'
# 3. open up browser devtools > network tab
# 4. back in the table, click the 'Xcode x.xx.xip' link then cancel the download box
# 5. in devtools, right click the download request > copy > copy curl link
# 6. paste the link below (it's really long) and append `$params`. eg. `curl ... $params`
}
# curl quits several times during download with exit code 18 (dunno why) so just resume the download
# if that happens
# code 56 is a network disconnect so let's wait longer for it to reconnect
exit_code=18
while [ "$exit_code" == 18 ] || [ "$exit_code" == 56 ]; do
getFile
exit_code=$?
if [ "$exit_code" == 18 ]; then
sleep 5
else
sleep 60
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment