Hooks in Pacman
Hooks in Pacman
Suyash Singh
Posted by Suyash Singh
on October 18, 2022
Photo by shark on Unsplash

Pacman hooks is pacman’s way of running pre and post tasks in the phase of package installation. It basically helps in automating things around package installation.

Applications

I personally use it to always maintain an up-to-date list of packages installed from the official repositories or from AUR — to always be ready for the scenario wherein I need to reinstall the system for any reason whatsoever.

Other potential applications of hooks commonly seen are to primarily automate the tasks around users and permissions management required before & after installation of certain packages. Additionally, hooks can be used to automate the cleanup process of the pacman cache directory /var/cache/pacman/pkg which stores all the package versions ever downloaded.

Conventions

Custom hooks should be present in the /etc/pacman.d/hooks directory and each hook file should have a .hook extension. The basic steps to write a hook can be understood here. Any scripts which is to be executed from the hooks should be placed inside the /etc/pacman.d/hooks.bin directory.

Summary

  • These things are useful to know if we want to automate certain aspects around package installation in arch based distros
  • We’d also use these hooks if we release a package for arch which:
    • needs the setup and registration of certain daemons with init systems like sytemd
    • needs custom permissions and user/usergroups configuration