install_xcode.sh
#!/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.' |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Xcode Command Line Tools Delete
Sep 16, 2019 Script to download & install XCode Command Line tools on OSX 10.7 or 10.8. Lifted from jedi4ever/veewee template. xcode-cli-tools.sh. It suits me fine most of the time, but you can change it by modifying the ‘Installation Directory’ build setting in Xcode and re-building from the command line. Build the pkg. Command Line Tools can be signed, but not directly notarized. You can however notarize a zip, dmg, or pkg file containing a Command Line.