I already configured email using the Arch wiki, so my system can easily sent emails, for example: mail -s "blabla" default would sent an email to the default configured email address.
or alternatively: printf "Subject: this is a subject\nthis is a body." | msmtp -a default
What I would like to do:
*after running pamac update -a --no-confirm, run a command that checks if a reboot is required after updating is finished. If the output of that command is “yes”, run a mail-s or msmtp coomand.
I have no clue how to do the part in bold. Could an expert point me in the right direction?
#!/usr/bin/env bash
reboot="(ucode|cryptsetup|linux|nvidia|mesa|systemd|wayland|xf86-video|xorg)"
if [[ $(which yay) =~ (yay) ]]; then
updates=$(checkupdates; yay -Qua)
else
updates=$(checkupdates)
fi
echo "$updates"
if [[ $updates =~ $reboot ]]; then
echo "Updating possibly requires system restart ..."
fi
Replace the line
echo "Updating possibly requires system restart ..."
with your send mail functionality - possibly injecting the content of the $updates variable into the mail body
@mithrial thanks! That seems to be the way to go. But it only focuses on pacman. I learned from this forum, the best practice is to update using pamac. So I am not sure if it would be effective if I use pamac to update?
@linux-aarhus thanks that is basically a copy/paste solution already
I am no expert at all… but it seems to be a whitelist of categories of packages. Could it be no reboot would be required (triggering a ‘false positive’) or, the opposite, for example if I run docker, perhaps a reboot is required (but not catched by this script) because docker is running and cannot be updated?
I just follow best practice. I am not worried at all, since updating attendedly for me = using the update manager GUI and hitting a button. This is the same as running that pamac command.