Installing and registering DetectX Swift with a single package

Yesterday a colleague on the MacAdmins Slack asked for some help creating a package that would both install and register DetectX Swift (DTXS) all in one shot. He was having trouble getting it to work with Jamf Composer even though a couple of us agreed that in theory his method should be working.

While admins are able to easily register DTXS after installation using management tools, in my case Munki and in his Addigy, the goal was to create a package that could be installed manually by less savvy techs or sporadically as needed via Apple Remote Desktop (ARD).

I had a little time at lunch today and decided to give it a try as a basic package using pkgbuild. Thankfully it worked perfectly right out of the gate, read on if you’d like the details.


I learned this method of packaging from Armin Briegel‘s great book, Packaging for Apple Administrators. I highly recommend purchasing it (and his other books) on Apple Books. They are well worth the price and your employer should cover the cost since they’ll help you do your job better, right?! Armin has graciously made the sample scripts from the book available for download on Github.


To start, setup your directory structure like below:

[code language=”text” light=”true”]
|—— Project
| |—— build-DetectXSwift.sh
| |—— payload
| | |—— Applications
| | | |—— DetectX Swift.app
| |—— scripts
| | |—— postinstall
[/code]


Copy the latest version of DetectX Swift.app into the Applications folder and then create the following two files:

#!/bin/sh

pkgname="DetectXSwift"
version="1.089"
identifier="com.sqwarq.${pkgname}"

PATH=/usr/bin:/bin:/usr/sbin:/sbin export PATH

projectfolder=$(dirname "$0")

pkgbuild --root "${projectfolder}/payload" \
         --identifier "${identifier}" \
         --version "${version}" \
         --install-location "/" \
         --sign "Developer ID Installer: Company, Inc. (XXXXXXXXX)" \
         --scripts "${projectfolder}/scripts" \
           "${pkgname}-${version}.pkg"

Edit the version number for the current version of DTXS you are packaging and optionally customize the identifier if you want it to be specific to your usage. If you are signing the package add your signing certificate information or otherwise remove line 15 completely.

#!/bin/bash

"/Applications/DetectX Swift.app/Contents/MacOS/DetectX Swift" register -key "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXX" -email "email@example.com"

Enter your DTXS registration key and email address in the postinstall file.

Once everything is in place, run ./build-DetectXSwift.sh to create the package: DetectXSwift-1.089.pkg

The resulting package will install DTXS into the Applications folder and register it with your Pro or Management license. It can be deployed remotely via ARD or users with administrative privileges can double click the package to install it manually.

Please take care in distributing the package because your DTXS registration key can be easily extracted with relatively little effort.

The downside of this method is that it isn’t automated. You’ll need to replace the application, update the build script and create a new package anytime DTXS is updated.  But since this is intended for infrequent use you could always just wait until the need arises to build instead of creating a new package for every update.

Let me know if you have any thoughts or questions and join us in the #detectx channel on Slack for more discussion around DTXS. For more information on building packages get Armin’s book!

Leave a Reply

Your email address will not be published. Required fields are marked *