Doing Some Cleaning

Tidying up my toys. (Image from Wikimedia)

My distribution point was gaining some bloat with a huge number of packages that were superseded or deprecated. I needed to do a clean out. I need a tool that will check which ones are used and list the rest.

I had a look at Spruce but it has one fatal flaw, it doesn’t look at patch policies. Now given my automation around patch management means I use patch policies a great deal that’s a problem. If my system is working perfectly then every package being used by a patch policy should also be used in a policy so it wouldn’t matter, but since it doesn’t always work perfectly I’m not prepared to risk removing a required package.

Time for me to write some Python. Hope you find this useful.

You’ll notice that it is chatty by sending text to stderr as it’s running. That’s really just so you have something to watch. The actual list goes to stdout so you can safely redirect to a text file.

https://github.com/Honestpuck/jamf-package-clean/blob/master/list-1.2.py

Run it as ./list-1.2.py > pack-list.txt

By the way, you’ll notice I have my login and JSS details in a preference file. This file is exactly the same format as used by python-jss or JSSImporter`. I just happen to have my own package importer for totally silly reasons.

Then the code to remove the packages is quite simple. I do go to the trouble of inserting some sanity checks.

https://github.com/Honestpuck/jamf-package-clean/blob/master/remove-1.0.py

The remove script reads from stdin so once you check pack-list.txt you just ./remove-1.0.py < pack-list.txt and stand well back while the demolition takes place.

You can find the latest version of the code at my Github repo – https://github.com/Honestpuck/jamf-package-clean.

All this action on my blog after a long absence is warming up to some long posts explaining how my current package and patch automation system works so bear with me on the journey.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s