Auto Munki Importer


What Is It?

Auto Munki Importer is a Perl script that will, based on the input data, determine if there is a new version of an application available. If a new version is available it will download the new file, extract it, and then import it into Munki.

It can handle static URLs, dynamic URLs where the URL or link to the URL changes based off the version (it can also handle landing pages before the actual download), and Sparkle RSS feeds. This generic approach should allow you to monitor most applications.

It supports downloads in flat PKGs, DMG (including support for disk images with licence agreements), ZIP, TAR, TAR.GZ, TGZ, and TBZ. It will import a single item (Application or PKG) from anywhere within the download, so the content doesn't have to be in the top level folder. This is achieved by using find to locate the item (e.g. the Adobe Flash Player.pkg from within the Adobe Flash download).


How to use it

After the script and its dependencies have been installed and configured, In terminal (or automatically via a Launch Daemon) run:-
autoMunkiImporter.pl [options]

Options

--data /path/to/data[.plist]

Path to the data plist, or a directory containing data plists. The data plist contains the configuration the script needs to download a particular application.

See Import Data Plist(s) for structure of the plist.

--download

Download the file to /tmp, and exits, without importing the item to Munki. It does not update the modified time or import to Munki.

--force-install-dependencies

Force install the required Perl Modules using the CPANM script.

--help | -h | -?

Show the usage and help text.

--ignoreModDate

Ignore the modified date and version info from the data plist. This will cause the item to be (re)imported into Munki.

--install-dependencies

Attempt to install the required Perl Modules using the CPANM script.

--reset

Resets the modified date of an application to the current modification date, without downloading or importing the item into Munki. Use this when the latest version of an application is in your Munki repo, so that this script doesn't attempt to re add it, of if you want to skip a version.

--settings /path/to/settings.plist

Optional path to a global settings plist. If not provided /Library/​Application Support/​autoMunkiImporter/​_DefaultConfig.plist is used. This plist contains the default settings for the script, some of which can be overridden by the data plists.

--silent

Suppresses output to STDOUT and STDERR. Verbose information is still written to the log. If --silent is provided in conjunction with --install-dependencies, --test, or --version it is ignored.

--test

Checks that the script passes its initial checks, and that it has permissions to write to the appropriate locations.

--verbose | -v

Show verbose output. If used a second time in addition to the verbose info, you will also get debug information. The verbose version of the output is logged when the logging level is set to verbose or lower. Debug information is also written to the log when verbose is provided twice.

If --silent is provided, it takes priority and suppresses all output to STDOUT.

--version

Prints scripts version to STDOUT.


How does it work?

Regardless of the type, the script runs through a set of stages to determine what it should do. These stages are:-

Pre-Requirements check
Ensure that all of the required items are present, and operational.

Determine Actual URL of download file
Based on the type, determine the final URL for the file, handling redirects. At the end of this stage we should have a URL that points to the file we want to download.

Determine if file has changed since last download
Using curl's --head feature, we look for the Last-Modified header, and compare it to any previously saved modification date. If the dates are different we assume it's a new version, and that it should be downloaded. This means we only ever download new versions, not copies of existing applications.

Download the new version
Check that the download is in a format that we support, and if so download it.

Prepare download for import into Munki
Extracts or mounts the download, and then uses find to find the item within the download to import into Munki.

Import into Munki
Imports the application into Munki using munkiimport.

Update Pkginfo and Data Plists
Copies any of the Munki keys into the Pkginfo file, and updates the data plist with the new modification date. A record of the import is saved within the data plist, and a copy is saved to the status (summary) plist.

Notify that an application has been imported
If email reports are enabled, send an email saying the script has imported the application to the configured email address.

Rebuild Catalogs
If make catalogs is enabled, rebuild all of the catalogs.