-
-
Save zchee/76b911df2d1a8b29e11d to your computer and use it in GitHub Desktop.
Script to download & install XCode Command Line tools on OSX 10.7 or 10.8. Lifted from jedi4ever/veewee template.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
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 | |
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')" -target / | |
hdiutil detach "$TMPMOUNT" | |
rm -rf "$TMPMOUNT" | |
rm "$TOOLS" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
trinitronx commented on Aug 6, 2014
@xbeta: Something like this should do what you want. If you're upgrading, you'll have to make sure to delete the old /Applications/Xcode.app application bundle first.
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.