A .pacnew file may be created during a package upgrade to avoid overwriting a file which already exists.
A .pacsave file may be created during a package removal, or by a package installation of a package that was removed.
These files require manual intervention from the user and it is good practice to handle them regularly.
Here is a Pacman hook to detect and list .pacnew files when found.
Looking for .pacnew files...
First create a script that we’ll call later with the pacman hook, we’ll name it check-pacnew and create it in /etc/pacman.d/scripts/ with a text editor:
#!/bin/bash
# List .pacnew files when found
pacnews=($(/usr/bin/pacdiff --output|grep -v pacsave))
nb="${#pacnews[@]}"
if [[ $nb > 0 ]]; then
echo -e "\e[1;31m$nb .pacnew found in system \e[0m"
printf "%s\n" "${pacnews[@]}"
fi
Ensure /etc/pacman.d/scripts/check-pacnew is owned by root and is executable!
Then create the actual pacman hook, it will be named check-pacnew.hook and should be created in /etc/pacman.d/hooks/:
[Trigger]
Operation = Upgrade
Type = Package
Target = *
[Action]
Description = Looking for .pacnew files...
Exec = /etc/pacman.d/scripts/check-pacnew
When = PostTransaction
NeedsTargets
With these two files in place, every time pacman will do an update, it will trigger the pacman hook, which will call the script, and output something like that if it finds a .pacnew file:
(19/22) Looking for .pacnew files…
.pacnew files found : 1/etc/security/limits.conf.pacnew
Cleaning Wine extensions and shit...
/etc/pacman.d/scripts/clean-wine:
#!/bin/bash
# Cleaning Wine extensions and shit...
rm -f /home/omano/.local/share/applications/wine-extension*.desktop
rm -f /home/omano/.local/share/icons/hicolor/*/*/application-x-wine-extension*
rm -f /home/omano/.local/share/mime/packages/x-wine*
rm -f /home/omano/.local/share/mime/application/x-wine-extension*
/etc/pacman.d/hooks/clean-wine.hook:
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = wine
[Action]
Description = Cleaning Wine extensions and shit...
Exec = /etc/pacman.d/scripts/clean-wine
When = PostTransaction
NeedsTargets
Placeholder...
/etc/pacman.d/scripts/xxx:
#!/bin/bash
# xxx
/etc/pacman.d/hooks/xxx.hook:
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = xxx
[Action]
Description = Xxx...
Exec = /etc/pacman.d/scripts/xxx
When = PostTransaction
NeedsTargets