Hear ye Archers - share your Pacman hooks
I've been using Arch for over a year now and have grown rather fond of it.
One of the things I found that help me manage day to day OS stuff are Pacman hooks.
Here're the hooks I use:
- Pug - Saves my Pacman and Aur package lists into Gists.
- Orphans - Runs
/usr/bin/pacman -Qtdqto list orphan packages after every update. - Pacman-cleanup - Keeps only the latest cache and the currently installed package.
- Archaudit - Runs
/usr/bin/arch-auditto list vulnerable installed packages from Arch CVE Monitoring Team data. - Informant - Prevents me from running updates if there's fresh Arch News since the last update. I use this with tmux-xpanes to manage multiple Arch install's without repetitive typing.
I'd love to hear what others are using!
EDIT: Found another cool hook: pacman-pstatus - A tool for being able to get a list of the packages and files which own them that have been deleted or replaced after package upgrades.
Edited 7 Nov 2019. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 247 · 100% up
- Kind
- Text
- ID
- dsnu81
75 comments
Overdue - "Get notified about running daemons that reference outdated shared libraries"
I use needrestart for that
So you create a post-transaction hook to run
/usr/bin/needrestartor the supplied pacman hook?Nice, I've added this to my list, cheers!
I'm from my phone, so can't share it atm but I have a hook that creates a btrfs snapshot of the system subvolume every time linux* || systemd* || glibc update. Most of the time if something critical breaks, they are the reason, so I always have the latest snapshot on me before a breakage.
Edit: the hook
btrfs-backupis a python script I wrote for myself and I don't think it'll be of any use to anybody except me but nonetheless you can take a look at it here. It'll require a bit of rewriting to work with different subvolumes than the ones I use thoughBetter do a snapshot of the whole system before each update. That’s my hook. But keep in mind to delete old snapshots, I only save the last 3 snapshots. btrfs FTW
Typically how big are those 3 snapshots, diff wise?
snapshots are a great hook
There is a hook for
zshthat rehashes binaries (so that they can be tab completed in your current session):https://wiki.archlinux.org/index.php/Zsh#On-demand_rehash
I dunno about hooks, but I always have this on:
Have it too, but 99% of the time can't even notice it everything goes so fast.. Exceptions are Go, Firefox and Kernel of course.
I use btrfs so I have snap-pac to take pre/post snapshots for every pacman transaction.
I also have it so that kernel modules are symlinked after a kernel upgrade so I don't have to restart right away:
The following checks for packages not in a sync database (I use aurutils so I keep all packages installed in a local database). This tells me if a maintainer silently removed a package from a repository:
The following tells me if I accidentally did a partial upgrade (just do pacman -Syu and choose "no" and then install package - that's a partial upgrade!) and have packages that need to be updated:
Backup boot partition before upgrading kernel (isn't on btrfs so snap-pac won't back up):
I don't really have a hook, but I have a neat script that goes through all the installed packages and produces a list of the *least* used ones, giving you an idea of what to uninstall if you are running out of space (or just want to debloat your install).
https://gist.github.com/mtekman/9769fa3eb28dd0dbdd1e8ce802157e95
This sounds interesting.
Does it need configuring, I took a quick look at it but it prints?
Compatible OS not detectedHuh weird, it should work fine on arch.
What do you get if you type in
uname -r | awk -F'-' '{print $NF}'into a terminal? It should printARCH.If not, then just change line 20 to read
local os=ARCHhttps://gist.github.com/mtekman/9769fa3eb28dd0dbdd1e8ce802157e95#file-pacman-last-used-sh-L20
Hmm I didn't even know this was a thing. Interesting.
https://github.com/saber-nyan/kernel-modules-hook : Avoid missing modules when updating the kernel
I tried that for a while, then removed it as I had to delete module directories for older kernel versions by hand.
linux-modules-cleanupservice normally does that for you. Did you enable it ?https://github.com/saber-nyan/kernel-modules-hook/blob/master/linux-modules-cleanup.service
Nice list, I just added the Informant hook, as I often get complacent and forego checking the news before updating, and when I do it is only with some of the "core" packages like linux, gcc, systemd, etc.
Sweet, might be nice to vote on the aur and star it on Github to encourage the dev.
Excellent list of hooks, op, and in the comments.
I wanted to use snapper but am not keen to change my ext4 system to btrfs just yet. So I use timeshift with the timeshift-autosnap hook that takes a snapshot before every upgrade.
Yea, I don't see myself making the move off ext4 for my daily driver/gaming desktop either.
I have the following hook which runs after pacman's mirrorlist is updated. The hook uses reflector to automatically filter the new list to https mirrors in the US, sorting them so that the fastest one is prioritized the highest:
This one is awesome - was about to suggest to put it on Arch Wiki, but it already is there, of course! Reflector - Pacman Hook - ArchWiki
P.S.: Shouldn't it run
sudo pacman -Syyuafter this? Pacman could be out of sync if the mirrors have been changed.Are orphaned packages common? I thought they were automatically removed if a package no longer needs them
They're not, but can accumulate over time if not pruned. My hook just prints them out, to remove them via hook was asked by /u/Newton_Gimmick and seems to have derailed the conversation.
Thanks for the post and starting an interesting discussion
You're welcome mate.
I have a hook that gives a message if the booted kernel has been updated.
/etc/pacman.d/hooks/99-z-kernel-reboot.hookPug is really cool but I'm not sure if it's wise to publish that information. Is there a way to make it use a local git repository?
Read the description, it uses a secret Gist via your Github account so nobody sees it. Besides I don't see how a list of packages is something to hide really.
It uses the gist tool - http://defunkt.io/gist/ which is designed to upload to Github.com not a local repo.
There's also https://aur.archlinux.org/packages/pacman-backup-hook/ which writes to a local file which won't be much use if you lose data and need the list to restore packages off.
This isn't a hook but since you mentioned Pacman-cleanup, you may find downgrade useful if you ever need to downgrade a package and it's not in your cache
EDIT:
LOL just installed pacman-cleanup-hook and this happened:
Hehe, yea, it's what got me interested in pacman hooks as I don't have a large SSD.
I've used downgrade, tried it first when I didn't make an Nvidia driver hook to recompile on new kernels and mistakenly thought it was a driver issue.
So how do I use orphans hook? I'd like to auto delete all orphans after each update...can you do that?
Read https://www.archlinux.org/pacman/alpm-hooks.5.htmlCreate a file named
orphans.hookand place it in/usr/share/libalpm/hooks/like so (updated):# cat /usr/share/libalpm/hooks/orphans.hook[Trigger]Operation = InstallOperation = UpgradeOperation = RemoveType = PackageTarget = *[Action]Depends = coreutilsWhen = PostTransactionExec = /usr/bin/bash -c "/usr/bin/pacman -Qtd || /usr/bin/echo '==> No orphaned packages found.'"#Exec = /usr/bin/bash -c "[[ if $(/usr/bin/pacman -Qtdq) = 0 ]] && /usr/bin/pacman -Rns $(/usr/bin/pacman -Qtdq) || /usr/bin/echo '==> No orphaned packages found.'"why does this depend on coreutils?
Is it save to do this after every update?
Deleted before we saved it.
You could but I feel managing packages should be done around pacman hooks instead of on a schedule.
That does the exact same thing through a bash script but also needs two systemd files.
Nice!
This is not wise. An AUR maintainer may orphan a package just because he/she doesn’t want to maintain it anymore so others can adopt it, even though the package is perfectly fine, in which case it may be re-adopted soon.
An orphan package is a package that was installed as a dependency, but no longer has the dependent package installed.
No, you're confusing maintainer abandoned aur packages with orphan packages which are not the same. Typically I would trim orphans to save SSD space.
So I added some of these hooks, but since I just upgraded my system I'm not entirely sure if they're running or not. More specifically, I want one of them (kernel-reboot.hook) to always run whenever I execute pacman, whether or not there were any upgrade or changes that time. Let's say I upgraded the kernel last time, didn't reboot, and now I've upgraded again. I want to be reminded that I should reboot every time I run pacman, basically.
However, I can't find any trigger that does this in the documentation. Do pacman hooks only ever execute if there was some change to the system? And just not at all otherwise?
That's not the job of the hook, you'll have to write something twisted like that yourself.
The hook checks for kernel upgrades first, take a look at what it's doing -
https://github.com/saber-nyan/kernel-modules-hook/blob/master/10-linux-modules-post.hook
https://github.com/saber-nyan/kernel-modules-hook/blob/master/10-linux-modules-pre.hook
What are you hoping to achieve with unnecessary reboots?
if you need reminders, there are other options, on Gnome you could use an extension like - https://extensions.gnome.org/extension/1010/archlinux-updates-indicator/
I’m not trying to reboot more than necessary, I’m trying to remind myself more often that I in fact need to reboot, because I’ve already upgraded my kernel.
But yeah, I’ve realized too that there’s just no mechanism for that.
I have an MSI with both an integrated Intel graphics card and an Nvidia GPU. Usually Nvidia is only used if I need an external monitor, so nouveau module is not always loaded.
I have a pre-installation hook that prints an alert message on the terminal if the module is loaded, and stops execution until the user acknowledges it.
Otherwise, if DKMS tries to remove the nouveau module during the upgrade process the whole system will froze, probably needing a live USB to boot and finish upgrade from arch-chroot.
That could be useful for notebook installs, post a link?
Sure, I was on the move when I wrote the previous message:
FILE: /usr/share/libalpm/hooks/65-nouveau.hook
FILE: /usr/local/sbin/alert-nouveau-loaded
Deleted before we saved it.
Not my work but find it handy, warns only when running kernel is updated or removed.99-z-kernel-reboot.hook
I got beaten
https://github.com/thaewrapt/xdg-menu-hook a hook for menu regeneration of fluxbox WM (+ some lightweight others) on install/update/remove.
I recommend
https://aur.archlinux.org/packages/paccache-hook
over pacman-cleanup one.
much more configurable and has reasonable console output (lists total amount of removed packages instead of every single file), and also comes with samer defaults