As I mentioned a few months back I have been working on informational hooks and a service to provide informational alerts for new users. I have written 3 hooks and a service to aid new users in learning how to maintain their system properly.
Anyone wishing to test a version of my post transaction hook and script that I've written please feel free to test it out to see the beautified output messages it provides at the end of the update process. Any feedback would be appreciated. Bare in mind it is still in the testing phase. I have been testing it in conjunction with 2 pre-transaction update hooks and a service. The service will provide further info such as if new update notices have been released and if a reboot will be required after update completion. The code is still messy, unfinished and a work in progress. I'm no pro coder, so don't laugh too loudly at it's current messy state.
The post transaction hook and script for those who'd like to test this version is as follows:
Create and save the following post transaction hook:
/etc/pacman.d/hooks/upgrade-adviser.hook
The hook contents:
#cat /etc/pacman.d/hooks/upgrade-adviser.hook
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Description = Check for pac* files and alien/orphaned packages ...
When = PostTransaction
Exec = /usr/bin/bash /etc/pacman.d/hooks.bin/upgrade-adviser.sh
The script that the hook launches is as follows:
/etc/pacman.d/hooks.bin/upgrade-adviser.sh
Script contents:
#!/usr/bin/env bash
#cat /etc/pacman.d/hooks.bin/upgrade-adviser.sh
uid="$(find /run/user/ -maxdepth 1 -mindepth 1 -type d | awk -F/ '{print $NF}')"
user="$(grep $uid /etc/passwd | sed 's/:.*//')"
display="$(DISPLAY=$(echo "$DISPLAY"))"
xdg_rd="$(XDG_RUNTIME_DIR=/run/user/$uid)"
xauth="$(XAUTHORITY=/home/$(grep $uid /etc/passwd | sed 's/:.*//')/.Xauthority)"
dbus_sba="$(DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus)"
export XAUTHORITY=/home/$user/.Xauthority
#export DISPLAY=:0
export DISPLAY=$(echo "$DISPLAY")
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$uid/bus"
su $(grep $uid /etc/passwd | sed 's/:.*//') -c "DISPLAY=$(echo "$DISPLAY") $(XAUTHORITY=/home/$(grep $uid /etc/passwd | sed 's/:.*//')/.Xauthority) DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus XDG_RUNTIME_DIR=/run/user/$uid notify-send 'Important update safety announcements to follow'"
pacfiles="$(pacdiff -o)"
orphans="$(pacman -Qtd | awk '{ print $1 }')"
black='\033[0;30m'
dk_gray='\033[1;30m'
red='\033[0;31m'
lt_red='\033[1;31m'
green='\033[0;32m'
lt_green='\033[1;32m'
yellow='\033[1;33m'
blue='\033[0;34m'
lt_blue='\033[1;34m'
purple='\033[0;35m'
lt_purple='\033[1;35m'
orange='\033[0;33m'
cyan='\033[0;36m'
lt_gray='\033[0;37m'
white='\033[1;37m'
default='\033[0m' # Default Color
# disable the 3 earlier Garuda hooks that this script replaces.
# comment out the 3 commands below after first run (not required).
mv /etc/pacman.d/hooks/pacnew-check.hook /etc/pacman.d/hooks/pacnew-check.hook.bak >/dev/null 2>&1 || true
mv /etc/pacman.d/hooks/orphans.hook /etc/pacman.d/hooks/orphans.hook.bak >/dev/null 2>&1 || true
mv /etc/pacman.d/hooks/foreign.hook /etc/pacman.d/hooks/foreign.hook.bak >/dev/null 2>&1 || true
# Create a Unix timestamp file to identify when the update was completed.
# sudo -Hiu $user sh -c "/usr/bin/echo -e "$(date +%s)" > /home/$user/.local/cache/last-upgrade.log" >/dev/null 2>&1 || true
# cancel if run in a tty
case $(tty) in /dev/tty[0-9]*)
exit 0 ;;
esac
printf "\n"
#
echo -e "${blue}* * * * * * * * * * * * * * *${default}" # blue colored output divider
#
printf "\n"
echo -e "${yellow}Return a list of all orphaned packages detected in the system ...${default}" # yellow colored textual output
printf "\n"
echo -e "${orange}$orphans:${default}\n" # orange colored output, (package version numbers stripped).
if [ $? -eq 0 ]; then
echo -e "${yellow}Double check package dependencies before uninstalling ...\n${default}" # yellow colored textual output
else
echo -e "${lt_green}No orphaned packages detected in the system ...\n${default}" # light green colored textual output
fi
#
echo -e "${blue}* * * * * * * * * * * * * * *${default}" # blue colored output divider
#
printf "\n"; echo -e "${lt_green}Return a list of all AUR (foreign/alien) packages installed on the system ...${default}" # green colored textual output
printf "\n"
echo -e "${green}$(pacman -Qm | awk '{ print $1 }')${default}"
if [ $? -eq 0 ]; then
printf "\n"; echo -e "${lt_green}Ensure that all AUR packages are updated to prevent breakages ...\n${default}" # green colored textual output
else
echo -e "${lt_green}No foreign packages detected in the system ...${default}" # light green colored textualual output
fi
#
echo -e "${blue}* * * * * * * * * * * * * * *${default}" # blue colored output divider
#
if [[ -n "pacfiles" ]]; then
printf "\n"; echo -e "${red}.pac* file(s) detected in the system ...${default}\n" # red colored textual output
## new experimental lines below:
# rm /tmp/pac-files.log 2> /dev/null || true
# pacdiff -o | tee /tmp/pac-files.log >/dev/null 2>&1 || true
# sudo -u $user bash -c "cat /tmp/pac-files.log > /home/$user/.local/cache/check-pac-files.log"
echo -e "${red}$pacfiles:${default}\n" # red colored textual output
# TESTING
#################################
su $user -c "$display $xdg_rd $xauth $dbus_sba /usr/bin/notify-send --urgency=critical 'Pac* files have been detected, most pacnew files should be merged, (very rarely immediately)'"
#################################
# TESTING ^^^
echo -e "${red}Most pacnew files require merging ...${default}" # red colored textual output
printf "\n"
echo -e "${red}Rarely pacnew files may require merging immediately ... ${default}" # red colored textual output
printf "\n"
echo -e "${red}Information regarding merging pacnew files can be found at the following links:${default}" # red colored textual output
printf "\n"
# the websites below can be replaced with Garuda specific content once it has been created.
# the links below are in purple colored text.
echo -e "${purple}https://wiki.archlinux.org/index.php/Pacman/Pacnew_and_Pacsave${default}"
printf "\n"
echo -e "${purple}https://wiki.archlinux.org/index.php/System_maintenance#Deal_promptly_with_new_configuration_files${default}"
printf "\n"
else
echo -e "${lt_green}No pacnew or pacsave files found in the system ...${default}" # light green colored textual output
fi
#
echo -e "${blue}* * * * * * * * * * * * * * *${default}" # blue colored output divider
#
printf "\n"
Make the script executable:
chmod +x /etc/pacman.d/hooks.bin/upgrade-adviser.sh
The script is still very messy as and it contains a lot of commented out functions that were for testing or are planned for future integration with the service. The first popup message is really only for testing purposes. The only popup that will occur with this script is when pac* files exist.
You don't need to create the hook to test the scripts functionality, but it would be most helpful if others tested it out under actual update conditions.
If you feel like testing this out, or simply have comments or suggestions about my code please feel free to post comments here.