-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtazpkg-notify
executable file
·115 lines (96 loc) · 3.17 KB
/
tazpkg-notify
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh
# TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
# tazpkg-notify - part of TazPkg
# Notification icon for TazPkg packages
# Recharging pkgs list can be done automatically at boot, so notify users
# if some updates are available. Also notify users if the packages list is too
# old and out-of-date or if no packages list found. This script should
# be run by the WM autostart script or ~/.xsession and needs a systray to
# sit in like in LXpanel or Tint2.
# Copyright (C) 2012-2015 SliTaz - GNU General Public License v3.
# Authors: See the AUTHORS files
. /lib/libtaz.sh
. /etc/slitaz/slitaz.conf
# I18n
export TEXTDOMAIN='tazpkg'
fifo=/tmp/$(basename $0).fifo
doc="file:///usr/share/doc/tazpkg/tazpkg.html"
alias notify=/usr/libexec/tazpkg-notification
cmd_recharge='tazbox su tazpanel pkgs#recharge'
cmd_up='tazbox su tazpanel pkgs#up'
installed=$(wc -l < "$PKGS_DB/installed.info")
text="$(_p \
'%s installed package' \
'%s installed packages' "$installed" \
"<b>$installed</b>")"
[ -f "$PKGS_DB/IDs" ] && mtime=$(find "$PKGS_DB/IDs" -mtime +10;)
up=0; [ -f "$PKGS_DB/packages.up" ] && up=$(wc -l < "$PKGS_DB/packages.up")
set_yad_action() {
echo -e "action:$1\ntooltip:$2\nicon:software-update-urgent" > $fifo
}
quit() {
echo "quit" > $fifo
# Clean-up
rm -f $fifo
exit 0
}
case $1 in
usage|help|*-h)
_n "Usage:"; echo " $(basename $0)"
;;
*)
# Sleep before displaying the notification icon
sleep 4
# Manage the I/O redirection from shell
rm -f $fifo; mkfifo $fifo
# Attach a file descriptor
exec 3<> $fifo
# Notification icon
yad --notification --listen --image='software-update-available' <&3 &
# Notification menu (right click)
cat > $fifo << EOT
menu:\
$(_n 'My packages' )!tazpanel pkgs#list!package-x-generic|\
$(_n 'Recharge lists' )!$cmd_recharge!system-software-update|\
$(_n 'Check upgrade' )!$cmd_up!system-software-install|\
$(_n 'TazPkg SHell' )!terminal -e tazpkg shell!utilities-terminal|\
$(_n 'TazPkg manual' )!tazweb --notoolbar $doc!slitaz-doc|\
$(_n 'Close notification')!quit!gtk-close
EOT
# Missing packages list
if [ ! -f "$PKGS_DB/packages.info" ]; then
tooltip="$(_ 'No packages list found')"
set_yad_action "$cmd_recharge" "$tooltip"
[ "$(notify "$tooltip" '1' "$(_n 'Recharge lists')")" = '1' ] && $cmd_recharge
quit
fi
# Too old packages list
if [ -n "$mtime" ]; then
tooltip="$(_ 'Your packages list is older than 10 days')"
set_yad_action "$cmd_recharge" "$tooltip"
[ "$(notify "$tooltip" '1' "$(_n 'Recharge lists')")" = '1' ] && $cmd_recharge
quit
fi
# Available upgrades
if [ "$up" -gt 0 ]; then
tooltip="$(_p \
'There is %s upgradeable package' \
'There are %s upgradeable packages' "$up" \
"<b>$up</b>")"
set_yad_action "$cmd_up" "$tooltip"
[ "$(notify "$tooltip" '1' "$(_n 'Check upgrade')")" = '1' ] && $cmd_up
quit
fi
# Nothing to do, close notification
tooltip="$(_ 'System is up to date')"
echo "tooltip:$tooltip\n$text" > $fifo
answer=$(notify "$tooltip"$'\n'"$text" '0' "$(_n 'Recharge lists')" "$(_n 'Check upgrade')")
case "$answer" in
1) $cmd_recharge;;
2) $cmd_up;;
esac
sleep 10
quit
;;
esac
quit