Simples .pkg
Mon, Jan 9, 2017Here is a very simple (and simplistic) example of building an OSX package using the pkgbuild
tool. We’ll just create and install a package containing a single command line executable (bash script) called pepperoni
.
$ mkdir -p ~/tmp/pepperoni/ROOT/usr/local/bin/
$ cat << EOF > ~/tmp/pepperoni/ROOT/usr/local/bin/pepperoni
#!/bin/bash
echo Pepperoni!
EOF
$ chmod +x ~/tmp/pepperoni/ROOT/usr/local/bin/pepperoni
$ pkgbuild --root ~/tmp/pepperoni/ROOT --identifier com.a4pizza.pepperoni --version 1.0 pepperoni.pkg
$ open pepperoni.pkg
Opening the .pkg
file fires up the Mac installer. After following the installer instructions you’ll be able to run the command.
$ pepperoni
Pepperoni!
That’s it!
But if you’d like to go further and check inside the package file you created you can do this:
$ lsbom `pkgutil --bom pepperoni.pkg`
And you can also check the files that were installed.
$ pkgutil --files com.a4pizza.pepperoni
usr
usr/local
usr/local/bin
usr/local/bin/pepperoni
The installer also keeps hold of a receipt of what was installed.
$ pkgutil --pkgs | grep pizza
com.a4pizza.pepperoni
If you later delete the installed files you can also forget the package as follows.
$ sudo pkgutil --forget com.a4pizza.pepperoni
$ pkgutil --pkgs | grep pizza
$
All gone!
I said this was a very simplistic example. You’ll obviously need to do a bit more work to add an update and uninstall capability, but hopefully this will give you a first foothold.