Skip to content

Instantly share code, notes, and snippets.

@sebsto
Created October 29, 2024 16:02
Show Gist options
  • Save sebsto/5a8b9e763190057dcb90c7a83d5a05eb to your computer and use it in GitHub Desktop.
Save sebsto/5a8b9e763190057dcb90c7a83d5a05eb to your computer and use it in GitHub Desktop.
Install Xcode from the command line
#!/bin/sh
echo "==========================="
echo "Installing required tools"
echo "==========================="
echo "Checking the current version of XCode"
xcode_version=$(xcodebuild -version)
echo $xcode_version
if [[ ${xcode_version} != *"$XCODE_REQUIRED_VERSION"* ]];then
echo "Build requires Xcode version $XCODE_REQUIRED_VERSION - upgrading now"
echo "Removing old versions of XCode"
sudo rm -rf /Applications/Xcode*.app
sudo rm -rf /Library/Developer/CommandLineTools
echo "Installing XCode $XCODE_REQUIRED_VERSION"
aws s3 cp "s3://$BUILD_BUCKET/$XCODE_INSTALLER_PATH" xcode.xip --no-progress
xip --expand xcode.xip
sudo cp -Rf Xcode.app /Applications
sudo installer -pkg /Applications/Xcode.app/Contents/Resources/Packages/XcodeSystemResources.pkg -target /
sudo installer -pkg /Applications/Xcode.app/Contents/Resources/Packages/CoreTypes.pkg -target /
sudo installer -pkg /Applications/Xcode.app/Contents/Resources/Packages/MobileDevice.pkg -target /
sudo installer -pkg /Applications/Xcode.app/Contents/Resources/Packages/MobileDeviceDevelopment.pkg -target /
echo "Installing XCode Command Line Tools"
aws s3 cp "s3://$BUILD_BUCKET/$XCODE_TOOLS_INSTALLER_PATH" xcode-cli.dmg --no-progress
hdiutil mount ./xcode-cli.dmg
sudo installer -pkg /Volumes/Command\ Line\ Developer\ Tools/Command\ Line\ Tools.pkg -target /
hdiutil unmount /Volumes/Command\ Line\ Developer\ Tools/
echo "Accepting the XCode license"
sudo xcodebuild -license accept
echo "Ensure XCode is set to the latest installed version"
sudo xcode-select -r
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcode-select -p
echo "Download the iOS Platform"
sudo xcodebuild -downloadPlatform iOS
echo "Verifying the updated version of XCode"
xcodebuild -version
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment