May 04, 2019 Install Xcode via command line. GitHub Gist: instantly share code, notes, and snippets. Nov 16, 2018 First you need to ensure you have macOS 10.14 and XCode 10 installed (with command line tools) and you need a current Apple developer account. Codesign your app with ‘hardened runtime’ using –options runtime. Now package your app into a.dmg (e.g. Using DropDMG). Then upload the.dmg to Apple’s servers.
#!/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 |
commented Oct 6, 2013
(thank you) |
Xcode Command Line Tools Download Dmg
commented Jan 7, 2014
Thanks for this! But it's only for CLI , is there something for upgrading xcode from command-line too? |
Xcode Command Line Build
commented Aug 5, 2014
@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. |
#!/bin/sh |
# |
# install_xcode.sh |
# |
# Created by Andrew McKnight on 9/24/15 |
# |
# takes a downloaded .dmg containing Xcode and installs it to a specified location/name, or defaults to /Applications and the DMG's filename |
# |
# parse possible switch options |
VERBOSE=false |
whilegetopts':hv' option;do |
case$optionin |
h) echo'usage: $0 [-h] [-v] ~/path/to/.../Xcode.dmg ~/path/to/.../install/app/bundle/ final-name-of-Xcode.app';exit ;; |
v) VERBOSE=true ;; |
?) echo'error: invalid option -$OPTARG';exit ;; |
esac |
done |
# remove the options from the positional parameters |
shift$(( OPTIND -1)) |
# get the parameters for paths, xcode name |
DOWNLOADED_DMG_PATH='${1}'# location of the downloaded DMG |
XCODE_INSTALL_NAME='${2}'# what the .app bundle should be named |
# if no install name is supplied, default to the name of the DMG |
if [[ -z'${XCODE_INSTALL_NAME}' ]];then |
XCODE_INSTALL_NAME=`find ${DOWNLOADED_DMG_PATH} -maxdepth 1 -exec basename {} ;| rev | cut -f 2- -d '.'| rev`'.app' |
fi |
XCODE_INSTALL_LOCATION='${3}'# where Xcode should be installed |
# if no custom install location is supplied, default to /Applications |
if [[ -z'${XCODE_INSTALL_LOCATION}' ]];then |
XCODE_INSTALL_LOCATION='/Applications' |
fi |
XCODE_INSTALL_PATH='${XCODE_INSTALL_LOCATION}/${XCODE_INSTALL_NAME}' |
if [[ $VERBOSEtrue ]];then |
echo'DOWNLOADED_DMG_PATH=${DOWNLOADED_DMG_PATH}' |
echo'XCODE_INSTALL_NAME=${XCODE_INSTALL_NAME}' |
echo'XCODE_INSTALL_LOCATION=${XCODE_INSTALL_LOCATION}' |
echo'XCODE_INSTALL_PATH=${XCODE_INSTALL_PATH}' |
echo'' |
fi |
# mount the disk image |
if [[ $VERBOSEtrue ]];then |
echo'hdiutil attach '${DOWNLOADED_DMG_PATH}'' |
fi |
hdiutil attach '${DOWNLOADED_DMG_PATH}' |
if [[ $VERBOSEtrue ]];then |
echo'' |
fi |
# prepare install destination if it doesn’t exist |
if [[ $VERBOSEtrue ]];then |
echo'mkdir '${XCODE_INSTALL_LOCATION}'' |
fi |
mkdir '${XCODE_INSTALL_LOCATION}' |
if [[ $VERBOSEtrue ]];then |
echo'' |
fi |
# get the canonical path to the Xcode app bundle in the DMG |
if [[ $VERBOSEtrue ]];then |
echo'XCODE_BUNDLE_PATH=`find /Volumes/Xcode -maxdepth 1 -name 'Xcode*.app'`' |
fi |
XCODE_BUNDLE_PATH=`find /Volumes/Xcode -maxdepth 1 -name 'Xcode*.app'` |
if [[ $VERBOSEtrue ]];then |
echo'XCODE_BUNDLE_PATH=${XCODE_BUNDLE_PATH}' |
echo'' |
fi |
# copy the app bundle to the install location |
if [[ $VERBOSEtrue ]];then |
echo'cp -R '${XCODE_BUNDLE_PATH}''${XCODE_INSTALL_PATH}'' |
fi |
cp -R '${XCODE_BUNDLE_PATH}''${XCODE_INSTALL_PATH}' |
if [[ $VERBOSEtrue ]];then |
echo'' |
fi |
# unmount the DMG |
if [[ $VERBOSEtrue ]];then |
echo'hdiutil detach /Volumes/Xcode' |
fi |
hdiutil detach /Volumes/Xcode |
if [[ $VERBOSEtrue ]];then |
echo'' |
fi |
# set new xcode as the preferred toolchain |
if [[ $VERBOSEtrue ]];then |
echo'xcode-select -s '${XCODE_INSTALL_PATH}'' |
fi |
xcode-select -s '${XCODE_INSTALL_PATH}' |
if [[ $VERBOSEtrue ]];then |
echo'' |
fi |
# accept the user license agreement |
if [[ $VERBOSEtrue ]];then |
echo'xcodebuild -license accept' |
fi |
xcodebuild -license accept |
if [[ $VERBOSEtrue ]];then |
echo'' |
fi |
# install command line tools |
if [[ $VERBOSEtrue ]];then |
echo''${XCODE_INSTALL_PATH}' -installComponents' |
fi |
'${XCODE_INSTALL_PATH}/Contents/MacOS/Xcode' -installComponents |
if [[ $VERBOSEtrue ]];then |
echo'' |
fi |
# done! |
echo'Finished installing Xcode.' |