Weekly News Summary for Admins – 2017-06-09

On Scripting OS X

To support Scripting OS X, consider buying one (or both) of my books. Thank you!

If you have already bought and read the books, please leave a review on the iBooks Store. Reviews are important to help new potential readers make the purchase decision. Thank you (again)!

Quiet week in the build-up for WWDC, both here on Scripting OS X and other places. Safe traveling and lots of fun to those going to San Jose! More news next week!

WWDC

News and Opinion

Updates and Releases

Support and HowTos

To Listen

Update 1.4 for ‘Packaging for Apple Adminstrators’

One of the advantages of digital books is they can be updated like software. This is one of the motivations I had for choosing iBooks as the format for my books.

The latest update (v1.4) for ‘Packaging for Apple Administrators’ is now available in the iBooks Store. If you have already purchased the book, iBooks should notify you that an update is available. If you have not bought the book yet then you can get it now and future updates as well!

This is the largest update I have done on this book so far. It contains a few sections that I had wanted to be in the book, but had to leave out for one reason or another:

  • new appendix with a printable Command Reference List
  • minor layout and design updates
  • added screen shot for ‘Show Files’ in Installer.app
  • added instructions for the productsign tool
  • added section on Bundle Relocation
  • added quickpkg to ‘Other Package Builders’
  • added Jamf Composer to ‘Other Package Builders’

The largest new part is the section on Jamf Composer. Composer is the packaging tool from Jamf, provided as part of the management application suite (or as a standalone). Composer has some strengths and many issues. The new section will walk through the process of creating packages with Composer and discuss the strengths and weaknesses and when other tools may be more appropriate.

Another new section is the new ‘Packaging Command Reference’, which are two pages with the most commonly used commands for working with packages. The pages are also available as a PDF in the book’s resources so you can print them and keep them near your workplace for quick reference.

If you like the book, please leave a rating on the iBooks Store. Your rating will help other admins find the book! Thank you!

Weekly News Summary for Admins – 2017-06-02

Quiet week in the build-up for WWDC, both here on Scripting OS X and other places. Safe traveling and lots of fun to those going to San Jose! More news next week!

Conferences

Updates and Releases

Support and HowTos

To support Scripting OS X, consider buying one (or both) of my books. Thank you!

If you have already bought and read the books, please leave a review on the iBooks Store. Reviews are important to help new potential readers make the purchase decision. Thank you (again)!

Weekly News Summary for Admins – 2017-05-26

On Scripting OS X

To support Scripting OS X, consider buying one (or both) of my books. Thank you!

If you have already bought and read the books, please leave a review on the iBooks Store. Reviews are important to help new potential readers make the purchase decision. Thank you (again)!

Updates and Releases

Posts and Opinion

Support and HowTos

To Listen

Relocatable Package Installers and quickpkg Update

In my book “Packaging for Apple Administrators” I show a great use of pkgbuild to wrap an application in a package installer:

$ pkgbuild --component /Applications/Numbers.app Numbers.pkg

If the application is not already in the /Applications folder, you have to add the --install-location:

$ pkgbuild --component /Volumes/Firefox/Firefox.app --install-location /Applications Firefox.pkg

This is great and wonderful, but has one drawback: the installers pkgbuild creates this way are ‘relocatable’. When the installer does not find the application in the target location, it will look if the application is installed elsewhere on the system. If it finds the ‘relocated’ application bundle, it will happily try to update it in the new location.

Usually this is not a big problem on managed systems. However, if users have copies of applications in unusual locations, e.g., because they do not have permission to install in /Applications or because they themselves are admins with dozens of versions in ~/Library/AutoPkg, then this can lead to unexpected behavior or failure.

The common solution to this is to create ‘non-relocatable’ installer packages.

What makes a pkg relocatable

The relocate element in the PackageInfo file in an installer package controls this behavior. You can see the PackageInfo file in Pacifist or with pkgutil:

$ pkgutil --expand Firefox.pkg Firefox_expanded
$ more Firefox_expanded/PackageInfo 

Among much other data you will see this xml element:

<relocate>
    <bundle id="org.mozilla.firefox"/>
</relocate>

This tells the Installer to look for an application bundle with the given identifier and install in that location. To disable this, you can replace the above element with an empty relocate element:

<relocate/>

Then installer will install or upgrade in the given install-location (e.g. /Applications) only.

You can apply this change to the expanded PackageInfo file with a text editor and re-create the pkg file with

$ pkgutil --flatten Firefox_expanded/ Firefox-nr.pkg

(‘nr’ for ‘non-relocatable’)

However, applying these steps after creating each package is tedious and error-prone, so we want to look for a better solution.

Telling pkgbuild to not re-locate

The pkgbuild man page mentions there is an option to create non-relocatable installer pkgs with the BundleIsRelocatable option in a ‘component property list’. This is great, since it is better to use documented options, rather than hacking the PackageInfo directly. However, to use the --component-plist option with pkgbuild you have to use the --root option rather than the --component option This requires a bit more effort.

First create a project folder:

$ mkdir -p Firefox/payload
$ cd Firefox

And copy the application to the payload directory:

$ cp -R /Volumes/Firefox/Firefox.app payload/

Then you can use pkgbuild’s --analyze to create a template component property list:

$ pkgbuild --analyze --root payload Firefox-component.plist
pkgbuild: Inferring bundle components from contents of payload
pkgbuild: Writing new component property list to Firefox-component.plist

You can then open the generated property list file in a text or property list editor. You will see several values for different settings and a list of ChildBundles. Change the value of the BundleIsRelocatable key from <true/> to <false/>. You can do this in the editor or with the plutil command:

$ plutil -replace BundleIsRelocatable -bool NO Firefox-component.plist

Then build the package with pkgbuild:

$  pkgbuild --root payload --identifier org.mozilla.firefox --version 53.0.3 --install-location /Applications --component-plist Firefox-component.plist Firefox-53.0.3.pkg

This will build the package installer with an empty relocate element.

Note: munki-pkg has an option suppress-bundle-relocation which achieves the same result.

QuickPkg

This approach can be useful but is still complicated. To simplify the creation I have updated my quickpkg tool to create non-relocatable packages by default. You can change the new default behavior with the --relocatable option.

$ quickpkg ~/Downloads/Firefox\ 53.0.3.dmg 
Firefox-53.0.3.pkg

Enjoy!

Weekly News Summary for Admins – 2017-05-20

On Scripting OS X

To support Scripting OS X, consider buying one (or both) of my books. Thank you!

If you have already bought and read the books, please leave a review on the iBooks Store. Reviews are important to help new potential readers make the purchase decision. Thank you (again)!

Updates and Releases

Posts and Opinion

Support and HowTos

Conferences

To Listen

Things 3 is out!

My favorite to-do-list manager that I keep returning to has gotten the long awaited update!
Things 3 from Cultured Code is out.

I have been using the beta for a while now and just love the application. Things 3 has plenty of features, but also a gorgeous and clean interface.

You can download a trial for the Mac version from their website. You can purchase the Mac, iPhone and iPad versions from the respective AppStores. Currently the app is on 20% introductory sale until May 25.

Tab Completion for autopkg

Tony Williams aka ‘honestpuck’ has built a script to enable tab-completion for autopkg in bash.

This means that you can type

$ autopkg s⇥

(where ⇥ is the tab key) and it will autocomplete to

$ autopkg search 

This will also work for recipe names:

$ autopkg run BBEdit⇥⇥
BBEdit.download  BBEdit.jss       BBEdit.pkg       
BBEdit.install   BBEdit.munki     

This is really useful. Auto-completion not only saves on typing, but helps to avoid errors.

Installing autocompletion in your profile

Tony has provided instructions on how to install the script with brew. However, it not hard to install this manually in your .bash_profile or .bashrc. First, clone the github repository on to your system (I keep all projects like this in an un-creatively named ‘Projects’ folder):

$ cd ~/Projects
$ git clone https://github.com/Honestpuck/autopkg_complete.git

This will download the project to autopkg_create. The file we need is the autopkg file inside that folder.

Then add the following lines to your .bash_profile or .bashrc:

if [[ -r "$HOME/Projects/autopkg_complete/autopkg" ]]; then
    source "$HOME/Projects/autopkg_complete/autopkg"
fi

You will need to adjust the path if you are using a different location. Basically these lines say: if this file exists and is readable, then read and interpret it as bash source. Since you need to define functions in the context of the shell, you need to `source` the file, rather execute it as script. (When you run the the file as a script, the functions will be defined in the context of the script, and then ‘forgotten’ when the script ends.)

Save your new profile and open a new Terminal window or type

$ source ~/.bash_profile

to update an existing shell.

Thanks again to Tony Williams, this is very useful!