Home > Mac administration, Mac OS X, Packaging, Scripting, Xcode > Building a Grand Unified Xcode 5.0.1 installer for Mavericks and Mountain Lion

Building a Grand Unified Xcode 5.0.1 installer for Mavericks and Mountain Lion

Apple has released Xcode 5.0.1 through the Mac App Store for all Macs running 10.8.4 and higher. The command line tools can be installed separately through the Xcode preferences, in the Downloads section.

For my users who are developers, I wanted to include Xcode 5.0.1 in their new machine builds and also install the command line tools automatically without needing to enter an Apple ID. I also wanted to build this installer as a flat package, so I’m shifting from my previous method using Iceberg to using Packages to build the installer package. With a little help from the Mac App Store, I was able to do this. See below the jump for the details.

With this Xcode installer, I decided to use the technique described here to capture a copy of the Xcode 5.0.1 installer from the App Store and then repackage that installer with the command line tools.
Screen Shot 2013-10-23 at 8.57.22 PM

Screen Shot 2013-10-23 at 9.25.36 PM

Once I had a copy of the Xcode installer package, here’s the process I used.

Building the installer

Download the latest Mountain Lion and Mavericks Command Line Tools for Xcode disk images from the Apple Developer site.

Set up a new Packages project and select Raw Package.
Screen Shot 2013-10-23 at 10.11.50 AM

In this case, I’m naming the project Xcode 5.0.1.

Screen Shot 2013-10-24 at 9.02.54 AM

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.

Screen Shot 2013-10-24 at 9.03.20 AM

Click on the Scripts tab in your Packages project.
Screen Shot 2013-10-24 at 2.42.14 PM

Select the following and drag them into the Additional Resources section of your Packages project:

Xcode 5.0.1 installer

Mountain Lion Command Line Tools for Xcode disk image

Mavericks Command Line Tools for Xcode disk image

Screen Shot 2013-10-24 at 9.27.57 AM

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.1 using the specified installer package in the working directory

/usr/sbin/installer -dumplog -verbose -pkg $install_dir/"Xcode 5.0.1.pkg" -target "$3"

if [[ ${osvers} -eq 8 ]]; then

#
# Installing the Xcode 5.0.1 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

if [[ ${osvers} -eq 9 ]]; then

#
# Installing the Xcode 5.0.1 10.9 Command Line Tools
#

# Specify location of Xcode command-line tools disk image

  TOOLS=$install_dir/command_line_tools_os_x_mavericks_for_xcode__late_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 preflight and postflight 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.

Screen Shot 2013-10-24 at 9.28.10 AM

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 3Creating a raw package project and Chapter 10Building a project.)

 

Testing the installer

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.1 and install it. The end result should be that Xcode 5.0.1 installs along with the correct Xcode command line tools for the installed OS without requiring an Apple ID.

  1. October 25, 2013 at 9:52 am
  2. October 28, 2013 at 4:24 pm

    Assuming you deploy these with Caspr, do you push these with a policy or make them Self Service?

    • October 28, 2013 at 4:26 pm

      Xcode is included with new machine builds. After that, the latest Xcode is available for installation via Self Service. I don’t push it.

  3. Patrick
    November 1, 2013 at 7:26 pm

    Is there an advantage to using the Apple Store installer package versus using the disk image from the Developer site?

    • November 3, 2013 at 3:56 am

      Patrick,

      The main advantage for me is that using Apple’s Xcode installer package means that Xcode is installed exactly the way that Apple intended.

      Using the installer also helps reduce the possibility of human error on my part, as I’m not reassigning permissions or manually ensuring that Xcode.app is being set to install into /Applications.

  4. Patrick
    November 14, 2013 at 11:58 pm

    Think there’s a typo with the 10.8 Command Line Tools installer location. It should be (two underscores before october):

    TOOLS=$install_dir/command_line_tools_os_x_mountain_lion_for_xcode__october_2013.dmg

    • November 15, 2013 at 12:17 am

      Apple may have changed the file name since the post went up, but that was the correct filename at the time. That said, always test, test, test.

      • Patrick
        November 15, 2013 at 2:43 am

        Yah I discovered the discrepancy in my testing of my Xcode 5.0.2 installer. I have a feeling someone at Apple made a change between now and the time your post went up.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: