Thursday, April 24, 2014

pkgbuild many MAS apps with bash

I wanted to quickly create pkgs for iWork and iLife from apps with an institutional ID receipt because I am experimenting with AutoDMG and Lightning.

It takes a bit of time for some of these to build and I didn't want to wait around so here is what I did…

Start an array by just typing array=( into the command line and then hitting <return>
admin_dist@golden ~ $ array=( 
Drag and drop the apps into the Terminal window hitting <return> after each
> /Applications/ 
> /Applications/ 
> /Applications/ 
> /Applications/ 
> /Applications/ 
> /Applications/
When they are all in finish off the array
> ) 
Now for the good stuff.  :D

For each path in the array
admin_dist@golden ~ $ for path in "${array[@]}"; do
 greedily chomp from the front to the last / using parameter expansion
> app_name="${path##*/}"
chomp from the end to the first period
> name="${app_name%.*}"
get the version of the thing at $path using command substitution and an assignment
> version=$(defaults read "${path}"/Contents/Info CFBundleShortVersionString)
build it with a pretty name
> pkgbuild --component "${path}" $HOME/Desktop/"${name}-${version}".pkg
> done

This will give you nice installer packages on the Desktop of the form "GarageBand-10.0.2.pkg".

Here is gist with a full script instead of interactive command line entries.

No comments:

Post a Comment