tazpkg view tazpkg-notify @ rev 583

Added tag 4.9.2 for changeset 3167d47c97c5
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 05 13:27:19 2012 +0200 (2012-04-05)
parents 11d71c5ac20a
children de952705379e
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) 2012 SliTaz GNU/Linux - GNU gpl v2
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 #
15 # I18n
16 . /usr/bin/gettext.sh
17 TEXTDOMAIN='tazpkg-notify'
18 export TEXTDOMAIN
20 fifo=/tmp/$(basename $0).fifo
21 panel="http://tazpanel:82/pkgs.cgi"
22 db="/var/lib/tazpkg"
23 doc="file:///usr/share/doc/tazpkg/tazpkg.html"
24 installed=$(ls $db/installed | wc -l)
25 text="$(gettext "Installed packages") <b>$installed</b>"
26 icon="/usr/share/pixmaps/tazpkg.png"
27 [ -f "$db/packages.list" ] && mtime=$(find $db/packages.list -mtime +10;)
28 [ -f "$db/packages.up" ] && up=$(cat $db/packages.up | wc -l)
30 # Notification icon
31 listen() {
32 # Manage the I/O redirection from SHell
33 rm -f $fifo && mkfifo $fifo
34 # Attach a file descriptor
35 exec 3<> $fifo
36 # Notification icon
37 yad --notification --listen --image=$icon \
38 --text="$(gettext "Checking packages lists") - $text" <&3
39 # Clean-up
40 rm -f $fifo
41 }
43 # Notication menu (right click)
44 menu() {
45 cat << EOT
46 menu:\
47 $(gettext "My packages")!tazweb $panel?list!tazpkg|\
48 $(gettext "Recharge lists")!tazweb $panel?recharge!tazpkg-up|\
49 $(gettext "Check upgrade")!tazweb $panel?up!tazpkg-up|\
50 $(gettext "TazPKG SHell")!terminal -e tazpkg shell!xterm|\
51 $(gettext "TazPKG manual")!tazweb $doc!text-html|\
52 $(gettext "Close notification")!quit!gtk-close
53 EOT
54 }
56 case $1 in
57 usage|help|*-h)
58 gettext "Usage:"; echo " $(basename $0)" ;;
59 *)
60 # Sleep before displaying the notification icon and
61 # sleep to let user read the tooltips.
62 sleep 4
63 listen &
64 sleep 2
65 menu > $fifo
66 sleep 6
67 # Missing packages list
68 if [ ! -f $db/packages.list ]; then
69 tooltip=$(eval_gettext \
70 "No packages list found - \$text")
71 echo "action:tazweb $panel?recharge" > $fifo
72 echo "tooltip:$tooltip" > $fifo
73 echo "icon:tazpkg-up" > $fifo && exit 0
74 fi
75 # Too old packages list
76 if [ "$mtime" ]; then
77 tooltip=$(gettext "Your packages list is older than 10 days")
78 echo "action:tazweb $panel?recharge" > $fifo
79 echo "tooltip:$tooltip" > $fifo
80 echo "icon:tazpkg-up" > $fifo && exit 0
81 fi
82 # Available upgrades
83 if [ "$up" -gt 0 ]; then
84 tooltip=$(eval_gettext \
85 "There are <b>\$up</b> upgradeable packages")
86 echo "action:tazweb $panel?up" > $fifo
87 echo "tooltip:$tooltip" > $fifo
88 echo "icon:tazpkg-up" > $fifo && exit 0
89 fi
90 # Nothing to do, close notification
91 tooltip=$(eval_gettext "System is up to date - \$text")
92 echo "tooltip:$tooltip" > $fifo
93 sleep 10
94 echo "quit" > $fifo ;;
95 esac
96 exit 0