graham gilbert

Mac administration and assorted nerdity

Creating Business Units and Groups in Sal Using a CSV

| Comments

Obviously I’m a little biased, but I love Sal. But, it can be a little tedious to get everything set up the first time if you have hundreds of Business Units and Machine Groups. I’ve quietly ignored the problem for a while, but then I saw this tweet pop up in my feed:

What say I Mr Bruienne? Like the man from Del Monte, I say YES!

The plan

We’re going to use a few of the parts that make Django and Docker awesome. We will:

  • Make a custom management command that will read in a CSV
  • The command will make the Business Units and Groups if they don’t exist
  • We’re than going to run it in a temporary Docker container when we’re ready to do the actual import. This is one of the strengths of Docker – we can spin up a linked container that will operate on the main database, but won’t interfere with your container serving the app.

First-boot-pkg Updated for Yosemite

| Comments

It seems like Yosemite introduced an undocumented change that requires any packages that are added an OS X installer (e.g. Netinstall or createOSXinstallPkg) be distribution style packages, or you get a nasty failure acompanied by one of the most unhelpful error messages ever.

To fix this, first-boot-pkg now builds distribution style packages.

London Apple Admins

| Comments

I’m delighted to say that the first (first meet that isn’t “let’s go to the pub and get drunk”, anyway!) London Apple Admins meetup is happening on the 3rd September at The Red Herring in St Pauls. I’d like to take all of the credit for organising it, but it was down to the hard work of Ben Toms. The theme this time is “this is what I’m working on at the moment”, so I’ll be talking about my new favourite toy, Docker.

If you’ll be in or around London on the 3rd September, please get yourself a ticket (they’re free) and come and have a beer or two whilst listening to some awesome talks by London based Mac Admins.

Personal Automation: Munki (Part 2)

| Comments

The first step to getting any Mac set up is to get some software onto it. I’m not going to cover how to set up Munki or AutoPkg – there are lots of other places for that information.

As a sysadmin, I’m forever testing things. Rather than destroy my own machine, I like to do this in Virtual Machines. My preferred virtualisation solution is VMware Fusion, but unfortunately it’s not very easy to deploy out of the box. You need to do a little bit of work to get it into a package that you can import into Munki, but fortunately the process is well documented on VMware’s site.

The next piece of ‘non standard’ software I need is Homebrew. The installation method listed on their site is to run a terminal command as the current user. The first part of this is obviously fine – Munki has several methods to run scripts (payload free packages, nopkg), but it runs everything as root. Fortunately, as I’m deploying my own machine, I can make some assumptions about where Homebrew will be installed. The first assumption I can make is that there will only be one user on the machine, and the second is that I’m going to be logged in most of the time (as my laptop is encrypted, it’s either off or logged in).

I’m going to utilise a nopkg pkginfo file to perform the installation. The first part of our script to install Homebrew is to make sure that a user (me!) is logged in. Homebrew doesn’t like being owned by root, so first we need to make sure that there is a user logged in.

1
2
3
4
5
6
7
8
#!/bin/bash

CURRENT_USER=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

if [ "$CURRENT_USER" == 'root' ]; then
    # this can't run at the login window, we need the current user
    exit 1
fi

So now we know that there’s a user logged in, and who that user is. Time to install Homebrew as the current user.

1
2
3
4
5
6
7
8
mkdir -p /usr/local
mkdir -p /usr/local/homebrew
mkdir -p /usr/local/bin
chown $CURRENT_USER:_developer /usr/local/homebrew
chown $CURRENT_USER:_developer /usr/local/bin

#download and install homebrew
su $CURRENT_USER -c "/bin/bash -o pipefail -c '/usr/bin/curl -skSfL https://github.com/mxcl/homebrew/tarball/master | (cd /usr/local ; /usr/bin/tar xz -m --strip 1 -C homebrew; ln -s /usr/local/homebrew/bin/brew /usr/local/bin/brew)'"

As we’re using a nopkg with Munki rather than a payload free package, we’ve not left any receipts, so Munki doesn’t know if Homebrew is installed. We’re going to use an installs array to tell Munki what to look for when determining whether Homebrew is installed or not.

1
2
3
4
5
6
7
8
9
<key>installs</key>
  <array>
      <dict>
          <key>path</key>
          <string>/usr/local/bin/brew</string>
          <key>type</key>
          <string>file</string>
      </dict>
  </array>

You might be crying “but Homebrew needs the Xcode Command Line Tools installed!” – and you’d be 100% correct. You have the option of importing the downloaded package into Munki, but I have adapted Tim Sutton’s script into a nopkg. To find out what’s installed, I ran fseventer and chose a random file to act as my installs array. I’ve posted the pkginfos for both the Xcode CLI tools and all of the Homebrew installs on Github.