tazpkg view tazpkg-notify @ rev 772

tazpkg-notify: auth/noauth links
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 08 09:54:28 2015 +0200 (2015-04-08)
parents 58f001f8e2bc
children 636b4e8dcf6a
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-2014 SliTaz GNU/Linux - GNU GPL v2
11 #
12 # Authors : Christophe Lincoln <pankso@slitaz.org>
13 #
15 . /lib/libtaz.sh
16 . /etc/slitaz/slitaz.conf
18 # I18n
19 export TEXTDOMAIN='tazpkg'
20 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
21 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
22 _p() {
23 local S="$1" P="$2" N="$3"; shift; shift; shift;
24 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
27 fifo=/tmp/$(basename $0).fifo
28 panelbase="http://tazpanel:82/pkgs.cgi"
29 panel="http://tazpanel:82/user/pkgs.cgi"
30 doc="file:///usr/share/doc/tazpkg/tazpkg.html"
32 installed=$(wc -l < $PKGS_DB/installed.info)
33 text="$(_p \
34 '%s installed package' \
35 '%s installed packages' $installed \
36 "<b>$installed</b>")"
38 [ -f "$PKGS_DB/packages.list" ] && mtime=$(find $PKGS_DB/packages.list -mtime +10;)
39 up=0; [ -f "$PKGS_DB/packages.up" ] && up=$(cat $PKGS_DB/packages.up | wc -l)
42 # Notification icon
44 listen() {
45 # Manage the I/O redirection from SHell
46 rm -f $fifo; mkfifo $fifo
48 # Attach a file descriptor
49 exec 3<> $fifo
51 # Notification icon
52 yad --notification --listen --image='TazPkg' \
53 --text="$(_ 'Checking packages lists - %s' "$text")" <&3
55 # Clean-up
56 rm -f $fifo
57 }
60 # Notification menu (right click)
62 menu() {
63 cat << EOT
64 menu:\
65 $(_n 'My packages' )!tazweb $panelbase?list!TazPkg|\
66 $(_n 'Recharge lists' )!tazweb $panel?recharge!tazpkg-up|\
67 $(_n 'Check upgrade' )!tazweb $panel?up!tazpkg-up|\
68 $(_n 'TazPkg SHell' )!terminal -e tazpkg shell!utilities-terminal|\
69 $(_n 'TazPkg manual' )!tazweb $doc!slitaz-doc|\
70 $(_n 'Close notification')!quit!gtk-close
71 EOT
72 }
75 case $1 in
76 usage|help|*-h)
77 _n "Usage:"; echo " $(basename $0)"
78 ;;
79 *)
80 # Sleep before displaying the notification icon and
81 # sleep to let user read the tooltips.
82 sleep 4
83 listen &
84 sleep 2
85 menu > $fifo
86 sleep 6
88 # Missing packages list
89 if [ ! -f $PKGS_DB/packages.list ]; then
90 tooltip="$(_ 'No packages list found - %s' "$text")"
91 (echo "action:tazweb $panel?recharge"
92 echo "tooltip:$tooltip"
93 echo "icon:tazpkg-up") > $fifo
94 exit 0
95 fi
97 # Too old packages list
98 if [ "$mtime" ]; then
99 tooltip="$(_ 'Your packages list is older than 10 days')"
100 (echo "action:tazweb $panel?recharge"
101 echo "tooltip:$tooltip"
102 echo "icon:tazpkg-up") > $fifo
103 exit 0
104 fi
106 # Available upgrades
107 if [ "$up" -gt 0 ]; then
108 tooltip="$(_p \
109 'There is %s upgradeable package' \
110 'There are %s upgradeable packages' $up \
111 "<b>$up</b>")"
112 (echo "action:tazweb $panel?up"
113 echo "tooltip:$tooltip"
114 echo "icon:tazpkg-up") > $fifo
115 exit 0
116 fi
118 # Nothing to do, close notification
119 tooltip="$(_ 'System is up to date - %s' "$text")"
120 echo "tooltip:$tooltip" > $fifo
121 sleep 10
122 echo "quit" > $fifo
123 ;;
124 esac
125 exit 0