An issue with Munki, especially if using AutoPkg, is that you can quickly amass many versions of software packages, which can fill up your repository volume. There are no automated ways of clearing out old versions of software, but in many cases there is no reason to keep them.
Removing a package involves the following process:
- Locate the imported package and delete it
- Locate the associated pkginfo file and delete it
If you’re organised, you’ll know exactly where every package is in the subdirectory structure of your Munki repository. But the repository can get hard to navigate. In which folder does Autopkg put Java 8? To where did your colleague import SPSS?
Use a GUI!
One way of removing packages is using the MunkiAdmin application. Simply right- or ctrl-click on an item in the Packages list, and select Delete Package. MunkiAdmin offers to delete the package and associated pkginfo file, and potentially the icon.
If you don’t wish to use MunkiAdmin, for instance if you are working remotely on a server via ssh, you may wish for an easy way to find and remove old packages using the command line. The munkitools don’t include a tool for this task. So I wrote a script to find items in the Munki repository that match an input, list the items in order of filename (so that associated .pkg and .plist files are adjacent in the list), and offer to delete each one in term.
Pressing ‘y’ deletes the item and moves on to the next item in the list. Pressing ‘n’ or any other character (except ‘q’) skips the item and moves on to the next. Pressing ‘q’ skips to the end of the list. After the end of the list has been reached, if anything has been deleted, ‘makecatalogs’ is run (for this to work, this script needs to be run on a Mac with munkitools installed and configured to point to your munki repository).
Make the script executable:
$ chmod +x /path/to/munkirm
To run the script:
$ /path/to/munkirm -d java
$ /path/to/munkirm -d chrome ---------------------------- MUNKI FILE REMOVAL TOOL ---------------------------- Usage: munkirm -d is case-insensitive part strings OK, e.g. goog Found these files: /Volumes/munki_repo/pkgs/apps/GoogleChrome-40.0.2214.115.dmg /Volumes/munki_repo/pkgsinfo/apps/GoogleChrome-40.0.2214.115.plist /Volumes/munki_repo/pkgs/apps/GoogleChrome-41.0.2272.118.dmg /Volumes/munki_repo/pkgsinfo/apps/GoogleChrome-41.0.2272.118.plist /Volumes/munki_repo/pkgs/apps/GoogleChrome-42.0.2311.90.dmg /Volumes/munki_repo/pkgsinfo/apps/GoogleChrome-42.0.2311.90.plist /Volumes/munki_repo/icons/GoogleChrome.png Delete /Volumes/munki_repo/pkgs/apps/GoogleChrome-40.0.2214.115.dmg (y/n/q)? y /Volumes/munki_repo/pkgs/apps/GoogleChrome-40.0.2214.115.dmg Deleted! Delete /Volumes/munki_repo/pkgsinfo/apps/GoogleChrome-40.0.2214.115.plist (y/n/q)? y /Volumes/munki_repo/pkgsinfo/apps/GoogleChrome-40.0.2214.115.plist Deleted! Delete /Volumes/munki_repo/pkgs/apps/GoogleChrome-41.0.2272.118.dmg (y/n/q)? n skipped Delete /Volumes/munki_repo/pkgsinfo/apps/GoogleChrome-41.0.2272.118.plist (y/n/q)? q skipped to end ### Catalogs have changed - running makecatalogs Hashing Adobe Acrobat XI Pro_3.png... Hashing Adobe-Premiere.png... ... [makecatalogs output] ... Created catalog /Volumes/munki_repo/catalogs/standard...
If you want to run this tool from any directory without requiring a path, copy it into
sudo cp /path/to/munkirm /usr/local/munki/