The Macintosh Guy
Posts about autopkg written by Honestpuck
https://s1.wp.com/i/favicon.ico
The Macintosh Guy
Here is my fourth post about PatchBot.

In the first post I gave a short summary of how the system works and introduced JPCImporter, the first AutoPkg custom processor.

In the second post I introduced patch management and the second custom processor.

In the third post I showed the third custom processor and the code to run it at the right time.

In the first three blog posts I explained (in great detail) how my system, PatchBot, works.

Today I am going to cover how to take the pieces and put them together into a complete system.

Continue reading →

After my last post Graham Pugh mentioned that the AutoPkg repository list is stored in the AutoPkg preference file as RECIPE_REPOS with the search order in RECIPE_SEARCH_DIRS.

He suggested doing a while loop on the defaults read output but I thought it was just fiddly enough a task in the shell that I might resort to a few lines of Python, so here it is, a Python script to dump out your repository list in search order. Tiny but it does the job.

(Thanks to Graham for taking the time to comment on the previous post, it was just what I needed to get me to spend the few minutes doing this.)

#!/usr/bin/env python3 # repos.py # print the list of AutoPkg repos in search order # NOTE: Totally lacking in any error checking or handling import plistlib from os import path plist = path.expanduser('~/Library/Preferences/com.github.autopkg.plist') fp = open(plist, 'rb') prefs = plistlib.load(fp) search = prefs['RECIPE_SEARCH_DIRS'] repos = prefs['RECIPE_REPOS'] # start at 3 to skip the built in ones for i in range(3, len(search)): print(repos[search[i]]['URL'])

Here’s a little one for you. I needed to keep the recipe repositories in sync across two machines.

AutoPkg will happily give you a repo-list- here’s part of mine:

autopkg repo-list /Users/Anthony.WILLIAMS/Library/AutoPkg/RecipeRepos/com.github.autopkg.48kRAM-recipes (https://github.com/autopkg/48kRAM-recipes) /Users/Anthony.WILLIAMS/Library/AutoPkg/RecipeRepos/com.github.autopkg.HobbitHardcase-recipes (https://github.com/autopkg/HobbitHardcase-recipes) /Users/Anthony.WILLIAMS/Library/AutoPkg/RecipeRepos/com.github.autopkg.MichalMMac-recipes (https://github.com/autopkg/MichalMMac-recipes) /Users/Anthony.WILLIAMS/Library/AutoPkg/RecipeRepos/com.github.autopkg.adobe-ccp-recipes (https://github.com/autopkg/adobe-ccp-recipes) /Users/Anthony.WILLIAMS/Library/AutoPkg/RecipeRepos/com.github.autopkg.arubdesu-recipes (https://github.com/autopkg/arubdesu-recipes) /Users/Anthony.WILLIAMS/Library/AutoPkg/RecipeRepos/com.github.autopkg.aysiu-recipes (https://github.com/autopkg/aysiu-recipes)

Unfortunately that isn’t in a form you can feed to AutoPkg’s repo-add command. We need something like sed to make it right. Here we go.

autopkg repo-list | sed "s#[^(]*(\([^)]*\)).*#\1#" https://github.com/autopkg/48kRAM-recipes https://github.com/autopkg/HobbitHardcase-recipes https://github.com/autopkg/MichalMMac-recipes https://github.com/autopkg/adobe-ccp-recipes https://github.com/autopkg/arubdesu-recipes https://github.com/autopkg/aysiu-recipes

Now we add them on the other computer. Pipe the above into repos.txt and then:

while read -r line ; do autopkg repo-add $line done < repos.txt

Now if AutoPkg had an option to list the repositories in search order rather than alphabetical…

Over the weekend I was feeling a little bored so I decided to try my hand at writing a shell script to add custom completion for autopkg to bash.

(tl;dr – the script is on GitHub.)

I found an example for the zsh shell which lacked a couple of features and I spent some time examining the script for brew so I wasn’t totally in the dark.

There are a number of tutorials available for writing them but none are particularly detailed so that wasn’t much help.

Writing Shell Scripts

The first thing I should say is that I find writing shell scripts totally different to writing for any other language. I probably write shell scripts incredibly old school, shell and C were the two languages I was paid to write way back in the 1980’s. It feels like coming home.

Continue reading →