2

I understand PackageMaker is now deprecated. We're now supposed to use pkgbuild/productbuild.

However, I can't seem to find an example for creating an installer for a kext. I was hoping to build the package as part of a build step from my kext Xcode project. So any bash/script files would be great.

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
Equinox2000
  • 576
  • 6
  • 17
  • Check out [Making OS X Installer Packages][1] [1]: http://stackoverflow.com/questions/11487596/making-os-x-installer-packages-like-a-pro-xcode4-developer-id-mountain-lion-re?rq=1 – catlan Jan 30 '13 at 12:19

1 Answers1

4

This answer is a seriously good guide for the general case.

For a kext specifically, after the Product -> Archive step, to generate the component plist, I found that I needed to 'cd' into the built archive package directory:

cd ~/Library/Developer/Xcode/Archives/2013-12-22/my-kext\ 22-12-2013\ 22.57.xcarchive

Then, the pkgbuild --analyze step looks like this:

pkgbuild --analyze --root ./Products/ my-kext.plist

The produced plist should contain a sensible-looking install destination for your kext under the RootRelativeBundlePath key. (typically /System/Library/Extensions/my.kext, or if codesigned and for 10.9+ it should be /Library/Extensions/my.kext) If not, fix the install location for your kext target in Xcode.

The main thing to watch out for when installing kexts is to get permissions right and to refresh the kext cache. pkgbuild seems to install the kext as root by default, so that's good. To force refreshing the kext cache, you need to update the modified time on /System/Library/Extensions (or /Library/Extensions if that's where you're installing to). You want to do this after your kext has been fully installed, so you'll need a postinstall script. Create a directory for it, e.g. ./scripts and create a file called 'postinstall' with the contents:

#!/bin/sh
touch /System/Library/Extensions

Then make it executable:

chmod +x postinstall

You can now build a generic package for your kext using:

pkgbuild --root ./Products/ --scripts ./scripts/ --component-plist my-kext.plist my-kext.pkg

For customisation, codesigning, etc., follow the instructions in catlan's linked answer - you can't beat them!

Community
  • 1
  • 1
pmdj
  • 22,018
  • 3
  • 52
  • 103
  • It appears that the `touch /System/Library/Extensions` command is not necessary any more with latest Xcode (6.4) any more when installing into `/Library/Extensions/`: The installer then appears to wait for the kext cache to be rebuilt automatically and only afterwards executes the postinstall script. – Thomas Tempelmann Jul 23 '15 at 11:42
  • I've tried building a distribution pkg, which worked. But when I tried to sign it, the productsigning worked as well, but when launching the pkg, the Installer would complain about an invalid signature. Can't figure out why, though. – Thomas Tempelmann Jul 23 '15 at 13:30
  • I suspect the kext cache thing depends on OS version more than Xcode version. If you're leaving out the `touch` command, ensure that you test your installer on all supported OS versions, **especially** the case where there is already a different version of the kext installed. (the touch is only needed in case of an upgrade/downgrade, not for a newly installed kext). For pkg signing, I'm no expert, but make sure you're using the installer developer ID certificate, not the application onne. – pmdj Jul 23 '15 at 15:53