#!/bin/sh | |
OSX_VERS=$(sw_vers -productVersion | awk -F "." '{print $2}') | |
# Get Xcode CLI tools | |
# https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex | |
# https://developer.apple.com/downloads/index.action | |
TOOLS=clitools.dmg | |
if [ ! -f "$TOOLS" ]; then | |
if [ "$OSX_VERS" -eq 7 ]; then | |
DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg | |
elif [ "$OSX_VERS" -eq 8 ]; then | |
DMGURL=http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_mountain_lion_april_2013.dmg | |
elif [ "$OSX_VERS" -eq 9 ]; then | |
DMGURL=http://adcdownload.apple.com/Developer_Tools/command_line_tools_os_x_mavericks_for_xcode__late_october_2013/command_line_tools_os_x_mavericks_for_xcode__late_october_2013.dmg | |
elif [ "$OSX_VERS" -eq 10 ]; then | |
DMGURL=http://adcdownload.apple.com/Developer_Tools/Command_Line_Tools_OS_X_10.10_for_Xcode_6.3.2/commandlinetoolsosx10.10forxcode6.3.2.dmg | |
elif [ "$OSX_VERS" -eq 11 ]; then | |
DMGURL=http://adcdownload.apple.com/Developer_Tools/Command_Line_Tools_OS_X_10.11_for_Xcode_7.3.1/Command_Line_Tools_OS_X_10.11_for_Xcode_7.3.1.dmg | |
elif [ "$OSX_VERS" -eq 12 ]; then | |
DMGURL=http://adcdownload.apple.com/Developer_Tools/Command_Line_Tools_macOS_10.12_for_Xcode_8.1/Command_Line_Tools_macOS_10.12_for_Xcode_8.1.dmg | |
elif [ "$OSX_VERS" -eq 14 ]; then | |
DMGURL=https://download.developer.apple.com/Developer_Tools/Command_Line_Tools_for_Xcode_11_GM_Seed/Command_Line_Tools_for_Xcode_11_GM_Seed.dmg | |
fi | |
curl "$DMGURL" -o "$TOOLS" | |
fi | |
TMPMOUNT=`/usr/bin/mktemp -d /tmp/clitools.XXXX` | |
hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT" | |
installer -pkg "$(find $TMPMOUNT -name '*.mpkg' -o -name '*.pkg')" -target / | |
hdiutil detach "$TMPMOUNT" | |
rm -rf "$TMPMOUNT" | |
rm "$TOOLS" | |
exit |
This comment has been minimized.
This comment has been minimized.
Thanks for this! But it's only for CLI , is there something for upgrading xcode from command-line too? |
This comment has been minimized.
This comment has been minimized.
@xbeta: Something like this should do what you want. If you're upgrading, you'll have to make sure to delete the old As I've since left my last company, those XCode URLs may not work forever, in which case you might want to download them from the App Store and mirror them yourself. The XCode dmg files were found via an excellent trick from Brian @cunnie at Pivotal Labs. Since XCode is a very large download, you should have enough time to grab it before the App Store app deletes the dmg. Just make sure that you're getting the complete file though! You can use a bash while loop with sleep to poll for the existence of the final download file and then copy it somewhere. You also might be interested in this great list of official versioned xcode URLs from Ben Chatelain's xcode-installer gem. |
This comment has been minimized.
This comment has been minimized.
@trinitronx, @xbeta: Broken link, use this permalink And @trinitronx: THANK YOU SO MUCH, Xcode's dmg is WAY TOO MUCH FILESIZE... Oh and one more thing: you may want to add 10.15 and 10.13 so it's future-proof (EDIT: It doesn't work on 10.7.5:
(fixed it by copy-pasting the os x 10.7 url from the file into |
This comment has been minimized.
This comment has been minimized.
@TheTechRobo: Yeah, this hasn't been updated in a while... I haven't had to bootstrap from scratch since 10.14, and my company is stubbornly refusing to let us upgrade to 10.15 Catalina. I've fixed the link rot for the Pivotal post for now. Maybe one day I can get a change to upgrade & test this. I do have a sprout-wrap fork where this Gist script is used as a sub-component to bootstrap Xcode CLT before I don't have time right now to work on this, but I do accept Pull Requests :-) |
This comment has been minimized.
(thank you)