Package Tasks
pkgtasks is a shell script library to ease writing POSIX-compliant shell scripts to handle common tasks during installation or removal of a package, e.g.,
-
creating groups and users needed by the package
-
creating and removing directories with special permissions and ownership,
-
copying example config files to their final locations during package installation, and removing them during package removal if they don't differ from the example ones,
-
reminding the user of files that may be customized after package installation.
Package tasks have the property of idempotence -- they may be invoked
multiple times, but the result must be the same as when invoked once, e.g.,
the shells
task adds an entry to /etc/shells, but will avoid adding the
same entry more than once.
Getting sources
The latest version of pkgtasks is 1.15 and was released on August 23th, 2017.
See the release notes for information about the changes in this and all previous releases.
Documentation
A script may load task modules to define shell functions to perform various tasks. A task module is loaded in a POSIX-compliant shell script by adding the following boilerplate to the script:
# Import the task loader.
: ${TASK_MODULE_DIR:=/usr/pkg/share/pkgtasks-1}
. "${TASK_MODULE_DIR}/load.subr"
# Load task modules.
task_load preinstall
The individual package tasks supported by pkgtasks are:
directories
: create and remove directories outside of package treefiles
: copy and remove configuration filesfonts
: regenerate X11 font indicesgroups
: create groups and warn about groups that may be removedicon_themes
: create caches in GTK+ icon theme directoriesinfo_files
: register and unregister GNU info filesocaml_findlib
: update OCaml findlib search pathspermissions
: check and set modes and permissions on special filesshells
: register and unregister login shellsshlibs
: update the shared library cacheusers
: create users and warn about users that may be removed
These package tasks support ${PKG_DESTDIR}
to manipulate the correct
filesystem paths for a destdir-installed package.
For convenience, these have been composed into larger meta-tasks:
preinstall
: tasks performed before files are installedpreremove
: tasks performed before files are removedpostinstall
: tasks performed after files are installedpostremove
: tasks performed after files are removed
There are also several utility tasks that may be used to write portable scripts:
cleanup
: run functions upon improper exitcompare
: compare two files for equalitycreatefile
: create empty filesdirwalk
: walk a directory tree using depth-first traversalecho
: write to standard output through a bufferlock
: create or release a lock filemakedir
: make a directory hierarchymaketemp
: make unique, temporary filesmatch
: match lines with a fnmatch(3) glob patternplatform
: determine the platform (operating system)quote
: quote strings for use with shell evalrandom
: generate random numbers (badly)refcount
: reference-count system resourcessay
: write to standard output with a tagsort
: sort lines from standard inputtaskfunc
: generic function hook for meta-taskstee
: duplicate writes to standard output into filestruthy
: evaluate truthinessvalid_options
: check validity of option stringsversion
: compare version stringswhich
: locate a program file in the $PATH
The documentation for each of these tasks is in man-page style in the header comments for each task module.