Apple has released Xcode 5.0.2 through the Mac App Store for all Macs running 10.8.4 and higher. While the command line tools for Mavericks are now included with Xcode, the command line tools for Mountain Lion can be installed separately through the Xcode preferences, in the Downloads section.
For my users who are developers, Xcode is part of their their new machine builds. I wanted to include Xcode 5.0.2 and also, where appropriate, install the command line tools automatically without needing to enter an Apple ID. With a little help from the Mac App Store, I was able to do this using Packages. See below the jump for the details.
I used the technique described here to capture a copy of the Xcode 5.0.2 installer from the App Store and then repackaged that installer with the Mountain Lion Xcode command line tools. Here’s the procedure I used.
Capture a copy of the Xcode 5.0.2 installer from the App Store
Download the latest Mountain Lion Command Line Tools for Xcode disk images from the Apple Developer site.
Set up a new Packages project and select Raw Package.
In this case, I’m naming the project Xcode 5.0.2.
Click on the Settings tab and set the following:
In the Post-Installation Behavior section, set On Success: to Do Nothing
In the Options section, check the box for Require admin password for installation.
Click on the Scripts tab in your Packages project.
Select the following and drag them into the Additional Resources section of your Packages project:
Xcode 5.0.2 installer
Mountain Lion Command Line Tools for Xcode disk image
The last pieces are removing any previous Xcode.app from /Applications and telling the Xcode installer and appropriate Command Line Tools for Xcode installer to run.
To remove any previous Xcode.app from /Applications, I’m using the following preinstall script:
#!/bin/sh # Remove existing copy of Xcode.app from /Applications if [ -d "$3/Applications/Xcode.app" ]; then rm -rf "$3/Applications/Xcode.app" fi
To install Xcode and the command line tools, I’m using the following postinstall script:
#!/bin/bash # Determine OS version osvers=$(sw_vers -productVersion | awk -F. '{print $2}') # Determine working directory install_dir=`dirname $0` # Install Xcode 5.0.2 using the specified installer package in the working directory /usr/sbin/installer -dumplog -verbose -pkg $install_dir/"Xcode 5.0.2.pkg" -target "$3" if [[ ${osvers} -eq 8 ]]; then # # Installing the Xcode 5.0.2 10.8 Command Line Tools # # Specify location of Xcode command-line tools disk image TOOLS=$install_dir/command_line_tools_os_x_mountain_lion_for_xcode__october_2013.dmg # Specify a /tmp/commandlinetools.XXXX mountpoint for the disk image TMPMOUNT=`/usr/bin/mktemp -d /tmp/commandlinetools.XXXX` # Mount the latest command line tools disk image to /tmp/commandlinetools.XXXX mountpoint hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen # Install the Xcode command line tools by searching the top directory of the # mounted disk image and installing any installer package found. Only the # Command Line Tools installer will be found by this search so it will be # installed without having the specify the current installer package's name /usr/sbin/installer -dumplog -verbose -pkg "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.pkg -o -iname \*\.mpkg \))" -target "$3" # Clean-up # Unmount the command line tools disk image from /tmp/commandlinetools.XXXX /usr/bin/hdiutil detach "$TMPMOUNT" # Remove the /tmp/commandlinetools.XXXX mountpoint /bin/rm -rf "$TMPMOUNT" fi
Once you’ve got the preinstall and postinstall script built, run the following commands to make the scripts executable:
sudo chmod a+x /path/to/preinstall
sudo chmod a+x /path/to/postinstall
Once completed, add the preinstall and postinstall scripts to your Packages project.
Last step, go ahead and build the package. (If you don’t know to build, check the Help menu for the Packages User Guide. The information you need is in Chapter 3 – Creating a raw package project and Chapter 10 – Building a project.)
Once the package has been built, test it by taking it to a test machine running 10.8.x and a separate test machine running 10.9 that do not have Xcode 5.0.2 and install it. The end result should be that Xcode 5.0.2 installs along with the correct Xcode command line tools for the installed OS without requiring an Apple ID.