forked from Chrysostomus/update-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-notifier
99 lines (90 loc) · 2.55 KB
/
update-notifier
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
. ~/.profile
trap 'rm /tmp/{pacmanupdates,aurupdates} 2>/dev/null' INT TERM QUIT EXIT
# check internet connection
connection()
{
curl -s --max-time 10 google.com >/dev/null 2>&1
}
# check if some known terminal is installed
# and print it to stdout
terminal()
{
if [ "$(command -v sterminal)" ]; then
echo "sterminal"
elif [ "$(command -v urxvt)" ]; then
echo "urxvt"
elif [ "$(command -v termite)" ]; then
echo "termite"
elif [ "$(command -v terminator)" ]; then
echo "terminator"
elif [ "$(command -v sakura)" ]; then
echo "sakura"
elif [ "$(command -v lxterminal)" ]; then
echo "lxterminal"
elif [ "$(command -v xfce4-terminal)" ]; then
echo "xfce4-terminal"
elif [ "$(command -v gnome-terminal)" ]; then
echo "gnome-terminal"
elif [ "$(command -v konsole)" ]; then
echo "konsole"
elif [ "$(command -v qterminal)" ]; then
echo "qterminal"
elif [ "$(command -v xterm)" ]; then
echo "xterm"
else
echo ""
fi
}
# list AUR updates and count them
aur_check()
{
if [ -x /usr/bin/yay ]; then
yay -Qua | tee /tmp/aurupdates | wc -l
elif [ -x /usr/bin/trizen ]; then
trizen -Qua | tee /tmp/aurupdates | wc -l
elif [ -x /usr/bin/pacaur ]; then
pacaur -Qua | awk '$2 == "aur" {print $3 $4 $5 $6}' | tee /tmp/aurupdates | wc -l
elif [ -x /usr/bin/yaourt ]; then
yaourt -Qua | grep "^aur/" | tee /tmp/aurupdates | wc -l
else
echo 0
fi
}
nb_pac=$(checkupdates | tee /tmp/pacmanupdates | wc -l)
if connection; then
nb_aur=$(eval aur_check)
else
echo "No internet connection, AUR updates skipped." 1>&2
fi
if [ -z "$TERMINAL" ]; then
TERMINAL=$(eval terminal)
if [ -z "$TERMINAL" ]; then
echo "ERROR: no known terminal emulator found, please update your TERMINAL environment variable." 1>&2
exit 1
fi
echo "export TERMINAL=\"$TERMINAL\"" >> ~/.profile
elif [ ! -x "$(command -v "$TERMINAL")" ]; then
echo "ERROR: '$TERMINAL' not found, please update your TERMINAL environment variable." 1>&2
if [ -z "$TERMINAL" ]; then
echo "ERROR: no known terminal emulator found, please update your TERMINAL environment variable." 1>&2
exit 1
fi
TERMINAL=$(eval terminal)
fi
if ((nb_pac>0 || nb_aur>0)); then
((nb_aur>0)) && nb_aur="+ ${nb_aur}" && cat /tmp/aurupdates >> /tmp/pacmanupdates
((nb_aur==0)) && unset nb_aur
answer=$(dunstify "You have ${nb_pac} ${nb_aur} updates" \
"$(cat /tmp/pacmanupdates)" -A Y,"Update now" -A N,Later)
case $answer in
Y) $TERMINAL -e update-help
;;
N)
;;
*) echo "'$answer' no match" 1>&2
;;
esac
else
dunstify "Your system is up to date" "No packages to update"
fi