tazpkg view tazpkg-notify @ rev 526

Add Spanish locales. Thanks Lucas
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Mon Aug 29 23:53:36 2011 +0200 (2011-08-29)
parents afe8175abd6f
children d8750abd87bd
line source
1 #!/bin/sh
2 #
3 # TazPKG Notify - Notification icon for Tazpkg packages. Recharging pkgs
4 # list can be done automatically at boot, so notifies users if some
5 # updates are available. Also notifies users if the packages list is too
6 # old and out-of-date or if no packages list found. This script should
7 # be run by the WM autostart script or ~/.xsession and needs a systray to
8 # sit in like in LXpanel or Tint2.
9 #
10 # Copyright (C) 2011 SliTaz GNU/Linux - GNU gpl v2
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 #
15 . /etc/slitaz/tazpkg.conf
16 LOCALSTATE="/var/lib/tazpkg"
18 # Include gettext helper script.
19 . /usr/bin/gettext.sh
21 # Export package name for gettext.
22 TEXTDOMAIN='tazpkg-notify'
23 export TEXTDOMAIN
25 up=$(cat $LOCALSTATE/packages.up | wc -l)
26 rel=$(cat /etc/slitaz-release)
28 # Kill the notification icon after user pressed on it.
29 kill_notification() {
30 for p in `ps | grep "yad --notification" | awk '{print $1}'`
31 do
32 kill -9 $p 2>/dev/null
33 done
34 }
36 # Message for up
37 up_msg() {
38 eval_gettext "<b>There are \$up upgradeable packages for your SliTaz \$rel</b>
39 You should upgrade your system to get all the latest fixes
40 and improvements from the SliTaz contributors"
41 }
43 # Message for list older than 10 days
44 old_list_msg() {
45 eval_gettext "<b>Your SliTaz \$rel packages list is older than 10 days</b>
46 You should recharge the list to check for updates"
47 }
49 # Message if packages.list is missing
50 no_list_msg() {
51 eval_gettext "<b>No packages list found on your SliTaz \$rel system</b>
52 You will need to recharge the list of mirrored packages
53 if you want to install packages or upgrade your system"
54 }
56 #
57 # Main GUI box for up packages
58 #
59 up_main() {
60 yad --text --width=400 \
61 --geometry="$NOTIFY_GEOM" \
62 --undecorated \
63 --title="TazPKG Notification" \
64 --image="tazpkg-up" \
65 --image-on-top \
66 --on-top \
67 --text="`up_msg`" \
68 --button="`gettext \"Upgrade:2\"`" \
69 --button="gtk-close:1"
70 }
72 # Notification icon for up packages
73 up_notify() {
74 yad --notification \
75 --image=tazpkg \
76 --text="`up_msg`" \
77 --command="tazpkg-notify upgrade"
78 }
80 # Main up function
81 up() {
82 # Store box results
83 main=`up_main`
84 ret=$?
85 kill_notification
86 # Deal with --button values
87 case $ret in
88 1) exit 0 ;;
89 2) tazweb http://tazpanel:82/pkgs.cgi?up & ;;
90 *) continue ;;
91 esac
92 }
94 #
95 # Main GUI box for missing packages.list
96 #
97 old_list_main() {
98 yad --text --width=400 \
99 --geometry="$NOTIFY_GEOM" \
100 --undecorated \
101 --title "TazPKG Notification" \
102 --image="tazpkg-up" \
103 --image-on-top \
104 --on-top \
105 --text "`old_list_msg`" \
106 --button="`gettext \"Recharge now:2\"`" \
107 --button="gtk-close:1"
108 }
110 # Notification icon if no packages.list
111 old_list_notify() {
112 yad --notification \
113 --image=tazpkg \
114 --text="`old_list_msg`" \
115 --command="tazpkg-notify no-list"
116 }
118 # Main missing packages.list function
119 old_list() {
120 # Store box results
121 main=$(old_list_main)
122 ret=$?
123 kill_notification
124 # Deal with --button values
125 case $ret in
126 1) exit 0 ;;
127 2) tazweb http://tazpanel:82/pkgs.cgi?recharge & ;;
128 *) continue ;;
129 esac
130 }
132 #
133 # Main GUI box for missing packages.list
134 #
135 no_list_main() {
136 yad --text --width=400 \
137 --geometry="$NOTIFY_GEOM" \
138 --undecorated \
139 --show-uri \
140 --title="TazPKG Notification" \
141 --image="tazpkg-up" \
142 --image-on-top \
143 --on-top \
144 --text "`no_list_msg`" \
145 --button="`gettext \"Recharge now:2\"`" \
146 --button="gtk-close:1"
147 }
149 # Notification icon if no packages.list
150 no_list_notify() {
151 yad --notification \
152 --image=tazpkg \
153 --text="`no_list_msg`" \
154 --command="tazpkg-notify no-list"
155 }
157 # Main missing packages.list function
158 no_list() {
159 # Store box results
160 main=$(no_list_main)
161 ret=$?
162 kill_notification
163 # Deal with --button values
164 case $ret in
165 1) exit 0 ;;
166 2) tazweb http://tazpanel:82/pkgs.cgi?recharge & ;;
167 *) continue ;;
168 esac
169 }
171 #
172 # Script commands
173 #
175 case $1 in
176 upgrade)
177 up ;;
178 old-list)
179 old_list ;;
180 no-list)
181 no_list ;;
182 *)
183 # Sleep first to let tazpkg upgrade on boot finish. Check if
184 # any upgrades, then for an old list and then if any lists at all
185 # (live or first boot)
186 sleep 10
187 [ "$up" -gt 0 ] && up_notify && exit 0
188 mtime=$(find /var/lib/tazpkg/packages.list -mtime +10;)
189 [ "$mtime" ] && old_list_notify && exit 0
190 [ ! -f $LOCALSTATE/packages.list ] && no_list_notify \
191 && exit 0 ;;
192 esac
194 exit 0