Creating useful Pacman hooks

only for demo/ideas purposes, we can make same action as pacman.conf "NoExtract"

Operation = Install
Operation = Upgrade
Type = Package
Target = ki18n

Description = Delete unnecessary locales
When = PostTransaction
Exec = /etc/pacman.d/hooks.bin/
# rm some files if it's not my language.
pacman -Qlq ki18n | grep "LC_MESSAGES" | grep -Ev "/de|/en" | grep -v "/$" | xargs truncate -s 0
pacman -Qlq ki18n | grep "LC_MESSAGES" | grep -Ev "/de|/en" | grep -v "/$"
# return to rm :

Work great, thank you :slight_smile:

Too bad that timeshift doesn't also use DESCRIPTION, then I wouldn't have to use it manually :wink:


[sgs@deepin ~]$ cat /etc/lsb-release 

Competition Question :wink:

Can I check when Deepin replaces the starter icon with a hook (Version update/upgrade)?

Script to restore own icons that Deepin changed
# - 15.05.2018 -
  echo "${0##*/} ersetzt das starter icon"
  echo "Keine Syntax für ${0##*/}"
test "${1}" = "-h" -o "${1}" = "-help" -o "${1}" = "--help" && Hilfe

# Check if the current user is "root" otherwise restart the script with "sudo"...
[ "$(whoami)" != "root" ] && exec sudo -- "$0" "$@"

# Instruct the Script to Abort for any command error...
set -e

cd /usr/share/icons/deepin/places/256/

cp /home/sgs/.icons/deepin-launcher.svg /usr/share/icons/deepin/places/256/deepin-launcher.svg

cd /usr/share/icons/deepin/apps/48/

cp /home/sgs/.icons/catfish.svg /usr/share/icons/deepin/apps/48/catfish.svg

exit 0

this ?

Operation = Install
Operation = Upgrade
Type = File
Target = usr/share/icons/deepin/apps/*/catfish.svg
# or Target = usr/share/icons/deepin/apps/48/catfish.svg
Target = usr/share/icons/deepin/places/*/deepin-launcher.svg

whe have for "Type" : File or Package
if File, dont write the first "/"


Ahh, Target does not mean target :), it means, look for change/Event.


target or Target , or no matter

</OT> :wink:

run hook (by Exec) only if Target is in Operation (Upgrade, Install, Remove) :wink:

with When=, we evaluate hook before or after transaction (PreTransaction, PostTransaction)


Timeshift Pacman Hook:

This is a revised version of my earlier timeshift hook with improved options for backup cancellation.

This hook will trigger an automatic Timeshift backup prior to installing a system upgrade. It also contains several methods to cancel the backup. This version includes automatic backup cancellation if another backup was recently made within an adjustable time frame. It also incorporates a feature that allows the cancellation of any backup with a 10 second (adjustable) countdown window via the keyboard. While the countdown is active you can cancel any backup by pressing ENTER

You may receive a popup error message when a timeshift snapshot is cancelled. The error message is irrelevant as it is only notifying about the failure of the scheduled timeshift backup (which was intended).

Preparation for creating the hook and scripts:

Create a sub-directory for the pacman hook:

sudo mkdir /etc/pacman.d/hooks

Create a sub-directory for pacman hook related scripts:

sudo mkdir /etc/pacman.d/hooks.bin

Now that we have the directories created to locate the hook and scripts we can proceed with writing them.

Timeshift Pacman Hook:

With a root capable text editor create the timeshift pacman hook:


Operation = Upgrade
Type = Package
Target = *

Description = pre-upgrade timeshift snapshot
When = PreTransaction
Exec = /bin/sh -c "sudo -Hiu user konsole -e /etc/pacman.d/hooks.bin/ | /etc/pacman.d/hooks.bin/"

It is sometimes difficult to use variables in pacman hooks, so there are portions of code that you will need to insert your own specific info.

Exec = /bin/sh -c "sudo -Hiu user konsole -e

In the above portion of the "Exec" line, replace "user " with your own username. Replace " konsole" with the name of the terminal emulator that you use on your system. Not all terminal emulators will launch properly using the "-e" (execute) parameter. The gnome terminal may be problematic to auto-execute with this script. Unlike many other terminal emulators gnome-terminal doesn't accept the "-e" parameter. If any knows the best method to auto-launch scripts with gnome-terminal please post the info.

This script must be used with a terminal emulator capable of accepting the "-e" (execute) parameter at launch. I do not know exactly which terminals are capable of this, but Yakuake and Konsole seem to handle this task well. You may need to experiment using different terminals to find the correct method of auto launching the script via a pacman hook.

This was a very difficult hook to get working properly with user keyboard intervention. I finally solved the problem by creating two separate scripts that require launching simultaneously via the hook. This method seems to work very well from my testing so far.

Timeshift Launch Script:

This script launches a timeshift backup automatically whenever an upgrade is initiated. The script also contains a method to automatically cancel any backup if another snapshot was taken recently. This function is to limit repeated snapshots within a short period of time. Repeated snapshots become a major annoyance when you run into an upgrade problem that you need to debug.

This script will cancel the snapshot if a prior snapshot was taken within the predetermined window of time you select. To change the time frame, replace "-mmin -60" (1hour) with another unit of time. If you would prefer the trigger to be set at two hours then simply change the time unit to "-mmin -120".

You will need to replace the path "/run/media/user/1TB/timeshift/snapshots-ondemand" in the script with your actual timeshift backup location. The backup is stored within the "/snapshots-ondemand" sub-directory inside the main timeshift directory.

The script also triggers a small GUI popup message when the backup is beginning.

Create the script to initiate (or automatically cancel) the timeshift snapshot:

find /run/media/user/1TB/timeshift/snapshots-ondemand -mmin -60 | grep $(date +%Y-%m-%d)
if [ $? -eq 0 ]; then
    echo "timeshift backup canceled, time threshold not met"
    sudo -Hiu user /bin/sh -c 'DISPLAY=:0 notify-send "Timeshift_Backup_Beginning"'
        echo " "
            echo "Initiating Pre-Update Timeshift Snapshot"
            echo " "
        echo "You have 10 seconds to cancel timeshift snapshot"
    /usr/bin/timeshift --create --comments "timeshift-pacman-hook-snapshot"

Save the script, then make the script executable:

sudo chmod +x /etc/pacman.d/hooks.bin/

Killshot Script:

This script allows for manual cancellation of the timeshift snapshot via keyboard intervention. It provides a 10 second (adjustable) countdown window during which you may cancel the snapshot. While the countdown is active you can cancel any backup by pressing ENTER

The number of seconds that the countdown window is open can be adjusted in this line:

for (( i=9; i>0; i--)); do

If you would like to increase the time window for cancellation to 20 seconds then adjust it as follows:

for (( i=20; i>0; i--)); do

The script also triggers a small GUI popup message when the backup is aborted.

Create the script to cancel the timeshift snapshot via keyboard intervention:

  echo "press any key to cancel timeshift snapshot"
      sleep 1
for (( i=9; i>0; i--)); do
    printf "\n$i seconds left to cancel snapshot  ... hit any key "
    read -s -n 1 -t 1 key
if [ $? -eq 0 ]; then
    sudo kill -2 `ps -ef|grep -i timeshift| grep -v grep| awk '{print $2}'`
        echo " "
            echo "aborting timeshift snapshot" 
      echo " "
   sudo -Hiu user /bin/sh -c 'DISPLAY=:0 notify-send "Timeshift_snapshot_aborted"'

Save the script, then make the script executable:

sudo chmod +x /etc/pacman.d/hooks.bin/

This is more complicated to write than other timeshift hooks, but far more versatile in my opinion.


This one need a special place but all scripts together are better, please could you link in post #1 to each hook with name orphans - timeshift - etc. , so new/user could find it quick?



I was planning on getting around to that, but Rome wasn't built in a day you know. :smile:

I've been busy with these silly little scripting projects of mine. The service I just wrote to restart dropped connections will really help a lot of people with flaky wifi I think.

@sgs did you get the above hook working well for you (and on which DE and terminals)

1 Like

I'm so sorry, I'm afraid not. But I'm sure you know how to do it and that it has to work.
I am on unstable, but with ""-mmin -60" (1hour)" I will test next time.

Thread: table of contents
I'd do the preliminary work if I knew what was relevant. LOL :smiley: :wink: :slight_smile:

My knowledge is unfortunately very limited respectively I have done everything already once, but I just can't remember it anymore :smiley:

1 Like

No big deal I'll get around to adding links. There's not so many hooks on here that it's hard to find an individual hook yet (but it's getting there).

1 Like

Geez, I can't find this hook I was looking for I wanted to play with.
Sure would be nice if there was a table of contents or something.



It's apparently time for me to create an irony or "I'm just kidding" button. :slight_smile:


As always, this message does not destroy itself.


Atheros QCA9377 Pacman Hook

Recently I have again read reports that the Atheros QCA9377 wifi adapter is suffering breakages on system updates. This issue usually only affects those who are using kernel 4.14 (or older).

Those using kernel 4.14 (and below) need to rename or delete the Atheros firmware-6.bin for this wifi adapter to work with older kernels. When using older kernels the firmware-5.bin must be used instead.

Wifi can be repeatedly broken after a system update, if the firmware-6.bin file is upated. This can be prevented by creating a pacman hook to automatically rename the firmware-6.bin to firmware-6.bin.bak after every update.

Atheros QCA9377 Pacman Hook

With a text editor create the Pacman hook:

Operation = Install 
Operation = Upgrade 
Type = File 
Target = lib/firmware/ath10k/QCA9377/hw1.0/firmware-6.bin

Description = Rename Atheros v.6 Firmware 
When = PostTransaction 
Exec = mv /lib/firmware/ath10k/QCA9377/hw1.0/firmware-6.bin /lib/firmware/ath10k/QCA9377/hw1.0/firmware-6.bin.bak 

This hook is only necessary for those using older kernels with the QCA9377 adapter. If you update to a kernel newer than 4.14 you will need to delete the pacman hook and rename firmware-6.bin.bak to its original name.

I have not personally tested this hook (as I do not own a QCA9377 adapter), but I'm fairly certain this should prevent any firmware update breakages in the future.

Please report on this hooks effectiveness if you have tested it with your QCA9377 adapter.


So once I got my idiocy out of the way, I LOVE the timeshift hook.
Impressive stuff.
I should never write stuff like this because I'll do sneaky stuff. Like with the countdown.

You have 3 seconds - press any key to stop the deletion of your /home directory
You have 2 seconds -  press any key to stop the Timeshift backup (just kidding about deleting home)
You have 1 second -  press any key to stop the Timeshift backup (Just kidding... deleting /home dir)

Window closes


Well its truly possible to execute deleting / directory with pacman hook.

Hello TBG. Thanks for your help, I tested your hook and doesn't work. When I reinstall linux-firmware, this creates the firmware-6.bin again and I have this message:

warning: could not get file information for usr/lib/firmware/ath10k/QCA9377/hw1.0/firmware-6.bin

Probably that means that the real target is from usr/lib... also I tested changing the target and Exec routes and doesn't work either.




Apologies, but I am not at home, so I do not have access to a Linux system to troubleshoot this issue. I will revisit the issue when I'm home again and let you know my findings.

1 Like

Don't worry TBG. Maybe I have an issue in my version, here:

Operation = Install
Operation = Upgrade
Type = File
Target = usr/lib/firmware/ath10k/QCA9377/hw1.0/firmware-6.bin

Description = Rename Atheros v.6 Firmware
When = PostTransaction
Exec = mv /usr/lib/firmware/ath10k/QCA9377/hw1.0/firmware-6.bin /usr/lib/firmware/ath10k/QCA9377/hw1.0/firmware-6.bin.bak 

Greetings :slight_smile:

What would I need to add to the pacman-list hook to get it to delete ones that are older than X days? Or would that require telling the hook to run a script and creating one in the hooks.bin directory?

Forum kindly sponsored by