How to automate the installation of Xcode?

I am trying to write a shell script that will install all our development tools and dependencies on a clean OSX machine.

Does anyone know a better approach to automate the installation of Xcode?

I do this to:

  • Document your development environment.
  • Speed ​​up the process of introducing new developers.
  • Follow the principle of automation - that’s all.
+4
source share
3 answers

Fully Automated Xcode Installation

First, login to the Apple Developer site and get the version of Xcode.dmg that works for your OSX version. You might want to take a couple of versions to support various OSX platforms (for example, 10.10 Yosemite, 10.9 Mavericks, etc.). Download dmg to a host file that you can access (for example: Amazon S3, Dropbox, your hosting provider of your choice, etc.)

Change DOWNLOAD_BASE_URL in the following script and rename the corresponding dmgs with the version and build number or add it to the script below:

 #!/bin/bash DOWNLOAD_BASE_URL=http://example.com/path/to/xcode/dmgs/ ## Figure out OSX version (source: https://www.opscode.com/chef/install.sh) function detect_platform_version() { # Matching the tab-space with sed is error-prone platform_version=$(sw_vers | awk '/^ProductVersion:/ { print $2 }') major_version=$(echo $platform_version | cut -d. -f1,2) # x86_64 Apple hardware often runs 32-bit kernels (see OHAI-63) x86_64=$(sysctl -n hw.optional.x86_64) if [ $x86_64 -eq 1 ]; then machine="x86_64" fi } detect_platform_version # Determine which XCode version to use based on platform version case $platform_version in "10.10") XCODE_DMG='XCode-6.1.1-6A2008a.dmg' ;; "10.9") XCODE_DMG='XCode-5.0.2-5A3005.dmg' ;; *) XCODE_DMG='XCode-5.0.1-5A2053.dmg' ;; esac # Bootstrap XCode from dmg if [ ! -d "/Applications/Xcode.app" ]; then echo "INFO: XCode.app not found. Installing XCode..." if [ ! -e "$XCODE_DMG" ]; then curl -L -O "${DOWNLOAD_BASE_URL}/${XCODE_DMG}" fi hdiutil attach "$XCODE_DMG" export __CFPREFERENCES_AVOID_DAEMON=1 sudo installer -pkg '/Volumes/XCode/XCode.pkg' -target / hdiutil detach '/Volumes/XCode' fi 

You may be interested in installing the Xcode command-line tools and bypassing the Xcode license agreement:

 curl -Ls https://gist.github.com/trinitronx/6217746/raw/58456d6675e437cebbf771c60b6005b4491a0980/xcode-cli-tools.sh | sudo bash # We need to accept the xcodebuild license agreement before building anything works # Silly Apple... if [ -x "$(which expect)" ]; then echo "INFO: GNU expect found! By using this script, you automatically accept the XCode License agreement found here: http://www.apple.com/legal/sla/docs/xcode.pdf" expect ./bootstrap-scripts/accept-xcodebuild-license.exp else echo -e "\x1b[31;1mERROR:\x1b[0m Could not find expect utility (is '$(which expect)' executable?)" echo -e "\x1b[31;1mWarning:\x1b[0m You have not agreed to the Xcode license.\nBuilds will fail! Agree to the license by opening Xcode.app or running:\n xcodebuild -license\n\nOR for system-wide acceptance\n sudo xcodebuild -license" exit 1 fi 

Alternative method

An alternative is to use this applescript that I created .

For use:

 git clone https://gist.github.com/6237049.git cd 6237049/ # Edit the script with AppleScript Editor to replace your APPLE ID and PASSWORD osascript Install_XCode.applescript 

You may also be interested in my answer here: How to download and install command-line tools for Xcode .

I would recommend another method using applescript method. An application depends on a hierarchy of user interface elements, which may not always remain the same for future versions of the App Store app on OSX. It seems fragile to me. Installing Xcode through the command line via dmg is probably the most reliable way.

+5
source

Starting with Xcode 4.3, it comes as an application package. When you first start the application, it will continue the installation. Since this is a beta version, it is still not fixed, but currently the installation packages after launch are in the application bundle in a directory called Contents / Resources / Packages.

So, depending on your environment, your installation script may simply copy the Xcode.app package to the application directory, and your users may complete the installation on first start. Or you can copy the package, and then manually install additional packages using the installer(8) utility. For more information on using the installer, see the man pages .

+2
source

Many of the things that exist to automate the download and installation are outdated. I was working on something for another project and I think that I have a good solution:

https://github.com/rockholla/macosa/blob/master/bin/macosa_xcode

And here is the download part:

https://github.com/rockholla/macosa/blob/master/bin/macosa_xcode_download

0
source

Source: https://habr.com/ru/post/1388206/


All Articles