Talk:DeveloperWiki:Pacman Hooks

From ArchWiki
Jump to: navigation, search

glib-compile-schemas

Used by 222 packages

Proposed Hook (glib-compile-schemas)

[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Operation = Remove
Target = usr/share/glib-2.0/schemas/*.gschema.xml
Target = usr/share/glib-2.0/schemas/*.gschema.override

[Action]
Description = Compile GSettings XML schema files...
When = PostTransaction
Exec = /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas

--City-busz (talk) 08:06, 23 April 2016 (UTC)

Thanks, I think that will work. --Heftig (talk) 08:22, 23 April 2016 (UTC)

hook script location

libalpm doesn't place any restrictions on where we store custom scripts for hooks, but I think we should store them all in the same place for the sake of consistency. I suggest '/usr/share/libalpm/hooks.bin/' in order to keep them near the hooks themselves. Apg (talk) 11:47, 23 April 2016 (UTC)

systemd-sysusers and systemd-tmpfiles

systemd-tmpfiles

Used by 52 packages

Proposed hook (systemd):

[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Target = usr/lib/tmpfiles.d/*.conf

[Action]
Description = Updating systemd-tmpfiles…
When = PostTransaction
Exec = /bin/sh -c 'while read -r f; do /usr/bin/systemd-tmpfiles --create "$f" ; done'
NeedsTargets

systemd-sysusers

Used by 29 packages

Proposed hook (systemd):

[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Target = usr/lib/sysusers.d/*.conf

[Action]
Description = Updating systemd-sysusers…
When = PostTransaction
Exec = /bin/sh -c 'while read -r f; do /usr/bin/systemd-sysusers "$f" ; done'
NeedsTargets

--AsamK (talk) 14:13, 23 April 2016 (UTC)

Thanks,
Heftig (talk) 19:15, 26 April 2016 (UTC)
Both of these fail on my system. systemd-tmpfiles and systemd-sysusers complain with a "No such file or directory" error. They seem to want an absolute path, starting with / as argument.
--Abdo (talk) 06:52, 27 April 2016 (UTC)
As stated on the systemd-sysusers(8) man page, if only the basename of the file is specified, it will search all directories specified in sysusers.d(5) man page. I am, as several other packages already do this, calling systemd-sysusers from post_install() of some of my packages. This hook would eliminate such need. But it should work with a trigger based only on the basename of the file, as is this one. And, as far as I know, there is no way to clean up the users after a package is removed, so such action would still need to be performed from post_remove().
--Grazzolini (talk) 23:14, 9 August 2016 (UTC)
systemd's philosophy on removing system users is that you shouldn't because there might still be files owned by the system user and removing the system user will free up it's UID to be reused.
--Stebalien (talk) 23:31, 9 August 2016 (UTC)
I agree with that philosophy. But some instances exists where the package at question only needs a user for running purposes so, the user can be created with any UID/GID (if not a reserved one), using "-" on sysusers configuration file and removing said user does not impact any leftovers on the filesystem. But these can and should be dealt individually and by the package itself, since you probably cannot do this easily with a hook.
--Grazzolini (talk) 00:08, 10 August 2016 (UTC)
No, that's actually the problematic case. If the sysusers conf file specifies a UID/GID, Arch can avoid re-using the UID/GID at the packaging level (never publish two packages that want to own the same UID/GID). The problem arises when a package doesn't care about it's UID/GID, asks systemd to randomly assign one, and then creates files owned by this UID/GID (in, e.g., /var/lib). However, I agree, there are some instances where packages want a new user but don't create any files owned by this user and this can be handled manually (although, IMO, it's not really worth it just to remove a line from a config file).
--Stebalien (talk) 03:52, 10 August 2016 (UTC)
Yes, packages getting any UID/GID and touching the filesystem, shouldn't remove the user afterwards. And the cases a package wants a user solely for runtime process, are few and the user removal afterwards should be done only if it is certain there was no file creation. I think the hook as is works and we shouldn't bother to change it further.
Grazzolini (talk) 11:13, 10 August 2016 (UTC)

while read

Suggested alternative (conveniently, texinfo already depends on findutils):

Exec = /usr/bin/xargs -i /usr/bin/install-info {} /usr/share/info/dir
NeedsTargets

--grawity (talk) 14:49, 23 April 2016 (UTC)

texinfo only depends on find due to its install scriptlet which is being replaced by these hooks. Allan (talk) 00:35, 24 April 2016 (UTC)

texlive file database update

Used in 27 packages with calls to either mktexlsr or texhash (one symlinks to the other).

Proposed hook (texlive-texmf):

[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Operation = Remove
Target = usr/share/texmf/*
Target = usr/share/texmf-dist/*
 
[Action]
Description = Updating texlive filename database...
When = PostTransaction
Exec = /usr/bin/mktexlsr

--abdo (talk) 09:49, 24 April 2016 (UTC)

I think you can put multiple Targets under one [Trigger], can't you? --grawity (talk) 10:08, 24 April 2016 (UTC)
Oh yes! I just tested it. Thanks!
Thanks, Heftig (talk) 19:15, 26 April 2016 (UTC)

gconf

[Trigger]
Type = file
Operation = Install
Operation = Upgrade
Target = usr/share/gconf/schemas/*.schemas

[Action]
Description = Installing GConf schemas...
When = PostTransaction
Exec = /bin/bash -c 'while read -r f; do f=${f##*/}; f=${f%.schemas}; /usr/bin/gconfpkg --install $f; done'
NeedsTargets
[Trigger]
Type = file
Operation = Remove
Target = usr/share/gconf/schemas/*.schemas

[Action]
Description = Removing GConf schemas...
When = PreTransaction
Exec = /bin/bash -c 'while read -r f; do f=${f##*/}; f=${f%.schemas}; /usr/bin/gconfpkg --uninstall $f; done'
NeedsTargets

(As a side note, gconf's own .install scriptlet is a bit weird)

--grawity (talk) 10:24, 24 April 2016 (UTC)

Thanks,
Heftig (talk) 19:15, 26 April 2016 (UTC)

Pacman treats the "#" as a comment so this fails. Allan (talk) 11:31, 27 April 2016 (UTC)

glib2: gio-querymodules

[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Operation = Remove
Target = usr/lib/gio/modules/*.so

[Action]
Description = Updating GLib GIO module cache...
When = PostTransaction
Exec = /usr/bin/gio-querymodules /usr/lib/gio/modules

--grawity (talk) 10:25, 24 April 2016 (UTC)

Thanks,
Heftig (talk) 19:15, 26 April 2016 (UTC)

fontconfig font cache

Used in 53 packages.

Proposed hook (fontconfig-cache):

[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Operation = Remove
Target = usr/share/fonts/*

[Action]
Description = Updating fontconfig font cache...
When = PostTransaction
Exec = /usr/bin/fc-cache -s

--abdo (talk) 10:29, 24 April 2016 (UTC)

The -f is unnecessary most of the time; existing packages have been removing it from their scripts. --grawity (talk) 10:59, 24 April 2016 (UTC)
Corrected.
Thanks,
Heftig (talk) 19:15, 26 April 2016 (UTC)

X font index

Used in 38 packages.

Proposed hook (xorg-font-index):

[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Target = usr/share/fonts/*/

[Action]
Description = Updating X font index...
When = PostTransaction
Exec = /bin/sh -c 'while read -r d; do mkfontscale "$d"; mkfontdir "$d"; done'
NeedsTargets
[Trigger]
Type = File
Operation = Remove
Target = usr/share/fonts/*/

[Action]
Description = Removing X font index...
When = PostTransaction
Exec = /bin/sh -c 'while read -r d; do if [ -f "$d/fonts.scale" ] && [ -f "$d/fonts.dir" ] && [ `find "$d" -maxdepth 1 -type f | wc -l` = "2" ]; then rm -f "$d"/fonts.{scale,dir}; fi; done'
NeedsTargets

Note: mkfontdir should run after mkfontscale, in case this hook ends up split as two separate hooks.

--abdo (talk) 11:21, 24 April 2016 (UTC)

This needs some more work. Dirs that were removed obviously shouldn't be touched. The indices should removed together with the target dir (if possible) if the dir contains no font files.
Heftig (talk) 19:15, 26 April 2016 (UTC)
Sorry about that, I forgot about the remove part... There is a second attempt above. Is there a better way to count files in a dir than the ls | wc -l thing?
--abdo (talk) 20:21, 26 April 2016 (UTC)
Well, not quite. This will probably create the index files on all parent directories up to /usr/share/fonts. At least mathjax installs fonts in a deep hierarchy. If this is not acceptable, an other option would be matching on files and producing a list of inner-most directories containing them.
--abdo (talk) 20:41, 26 April 2016 (UTC)

Suggestion: update-ca-trust

Here's a hook I recently added to one of my private packages, which will (should/seems to successfully) rebuild the CA certificate trust store whenever anchors change:

[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = File
Target = usr/share/ca-certificates/trust-source/anchors/*

[Action]
Description = Rebuild CA certificate trust sources
When = PostTransaction
Exec = /usr/bin/update-ca-trust

Emlun (talk) 18:20, 26 April 2016 (UTC)

Thanks,
Heftig (talk) 19:15, 26 April 2016 (UTC)

bashisms

Pacman requires bash to be present, but I don't remember anything about it requiring /bin/sh to be bash as well. Since read -r is a bashism, it should be only used with /usr/bin/bash -c, not with /bin/sh -c. --grawity (talk) 13:05, 27 April 2016 (UTC)

read -r is not a bashism, see man 1 read. read without a variable and with any other parameter than -r would be a bashism.--AsamK (talk) 09:20, 1 May 2016 (UTC)
Ah, thanks. My mistake. --grawity (talk) 09:25, 1 May 2016 (UTC)

Suggestion: Register binary formats

Currently, the only package in the repos that registers binary formats is mono (although there is a package for registering windows executables in the AUR).

[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Target = usr/lib/binfmt.d/*.conf

[Action]
Description = Installing binary formats...
When = PostTransaction
Exec = /usr/bin/systemctl restart systemd-binfmt

Note: There's no reason to do anything on Remove because binary formats can only be unregistered by rebooting.

--Stebalien (talk) 19:59, 10 May 2016 (UTC)