Building an Installer — Part 2

Running the installer from a script.

C4
The C4 Dev

--

In the last post we built a basic installer using the following command:

pkgbuild --root ./files --identifier com.test.travis --version 1 --install-location /Users/$USER/Desktop/files test.pkg

But, we don’t want to have to copy and paste all that nonsense into Terminal every time we want to run something. Workting with terminal is a pain in the ass when you want to change a small variable, or you make a typo. So, we want to run command-line code from a script and make life much easier.

1. Create a new text file and call it basicInstaller.sh (you can use whichever text editor you have, I use TextMate). Inside the file add the line of code from above.

This is what the script file looks like, with only a single line of code

2. With this file on the desktop, go back to Terminal and run:

sh basicInstaller.sh

Which looks cleaner, is easier to read and allows us to edit the contents of the script without having to copy / paste a bunch of ugly stuff into Terminal.

A little clearer than the previous terminal window with a long command in it

The script part of this is a real gem. It means that we can add a bunch of commands to a single file and run them from one simple line in Terminal.

3. The next step comfirms that our approach is good. What we want to do is make sure that we can work with files that are deep within Xcode. So, we’re going to take specific folder and copy its contents onto the desktop.

The following command looks nasty, but it’s not much different than before:

pkgbuild --root /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project\ Templates/Application/C4\ Single\ View\ Application.xctemplate --identifier com.test.travis --version 1 --install-location /Users/$USER/Desktop/newFiles test.pkg

Instead of copying from ./files we copy a folder from within Xcode, the one called C4 Single View Applcation.xctemplate which will eventually be the target for our installer.

4. Swapping the new command into our shell script and running it creates a new test package. After running the installer package, a quick look into the newFiles folder shows that there are now 4 new files instead of the original test image.

The four files that show up

We’ve made it easer to run a script from a shell (.sh) file, and we’ve targeted the right location that we want to work with inside Xcode. This means that what we want to do (i.e. build a dynamic and robust installer that puts specific files in weird places on our machine) is possible.

--

--

C4
The C4 Dev

Code, Creatively. An open-source API for iOS.