George Garside Blog

A place of many ramblings about macOS and development. If you find something useful on here, it's probably an accident.

Manual pages for packages in Alpine Linux are available as separate packages with a -doc suffix. When you’re installing a package such as apk add git you’ll miss out on the man pages unless you also apk add git-doc.

You can do both at the same time with apk add git git-doc. Generally, use the following to install a package and its manual pages documentation.

apk add <package> <package>-doc
Code language: plaintext (plaintext)

I came up with the following one-liner to install all these *-doc packages for all * packages currently installed:

apk list -I | sed -rn '/-doc/! s/([a-z-]+[a-z]).*/\1/p' | xargs -tI§ apk add §-doc
Code language: Bash (bash)
  1. List all installed packages using apk.
  2. Filter this list by
    • Removing all *-doc packages, since we can ignore trying to install documentation for the existing documentation packages.
    • Extracting the package name without the version number.
  3. For each package, using apk to install that package name with -doc suffix.

However, the above command is rather slow, since it has to run the mdocml trigger to build the man pages for each install rather than at the end.

Depending how long this takes on your machine (how many other manuals you have on your system), it might be more efficient to run apk add with all the packages appended. This is more difficult since I can’t find a way for apk to ignore errors. --force-broken-world means you have to clean up the world afterwards by removing all the packages that provide ‘unsatisfiable constraints’. I came up with the following solution by adding an awk into the pipeline.

apk list -I | sed -rn '/-doc/! s/([a-z-]+[a-z]).*/\1/p' | awk '{ print system("apk info \""$1"-doc\" > /dev/null") == 0 ? $1 "-doc" : "" }' | xargs apk add
Code language: Bash (bash)

The awk runs apk info $1-doc for each $1 package, which returns a status code of zero if the package exists (indicating it can be apk added and non-zero if not. This is used as an additional filter to determine which packages to attempt installation.

Leave a Reply

No comments