diff options
author | Dmitrii Morozov <snoopdesigns@gmail.com> | 2024-03-11 18:16:46 +0100 |
---|---|---|
committer | Dmitrii Morozov <snoopdesigns@gmail.com> | 2024-03-11 18:16:46 +0100 |
commit | 0e3daba82add5e6777c905a09f1d29fdf2615ddd (patch) | |
tree | eb6bcba108ec78676d0d9e61b57ecc63c3adccc2 /pacman-update-indicator | |
parent | 30ab3ef9aeb30dbe11f4645be31fb439fd139531 (diff) |
Pacman updates indicator
Diffstat (limited to 'pacman-update-indicator')
-rwxr-xr-x | pacman-update-indicator/pacman-update-indicator | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/pacman-update-indicator/pacman-update-indicator b/pacman-update-indicator/pacman-update-indicator new file mode 100755 index 0000000..12f6f2c --- /dev/null +++ b/pacman-update-indicator/pacman-update-indicator @@ -0,0 +1,56 @@ +#!/bin/bash + +CHECKUPDATES=checkupdates +PACMAN_UPDATE="pacman -S nano" + +get_terminal() { + terms=(gnome-terminal rxvt urxvt) + for t in ${terms[*]} + do + if [ $(command -v $t) ] + then + detected_term=$t + break + fi + done + echo $detected_term +} + +notify() { + result=$(notify-send --action=install=Install --action=cancel=Abort "Pacman updates available" "The following updates available:\n\n$1\n\nWould you like to install them?") + if [[ "$result" == "install" ]]; then + return 0 + else + return 1 + fi +} + +invoke_pacman_update() { + if is_superuser; then + echo "Running as superuser" + $TERMINAL -e bash -c "$PACMAN_UPDATE" + else + echo "Runnning with sudo" + $TERMINAL -e bash -c "sudo $PACMAN_UPDATE" + fi +} + +is_superuser() { + if [ "$EUID" -ne 0 ]; then + return 1 + else + return 0 + fi +} + +main() { + updates_available=$($CHECKUPDATES) + if [ -n "${updates_available}" ]; then + if notify "$updates_available"; then + invoke_pacman_update + fi + fi +} + +TERMINAL=$(get_terminal) +main |