tazpkg view tazpkg-notify @ rev 730

pkgs.cgi: html: remove "$SCRIPT_NAME" and replace "&" with "&".
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sun Dec 28 05:10:28 2014 +0200 (2014-12-28)
parents 1ab24812ad7e
children 0bda827841cd
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 panel="http://tazpanel:82/pkgs.cgi"
29 doc="file:///usr/share/doc/tazpkg/tazpkg.html"
31 installed=$(wc -l < $PKGS_DB/installed.info)
32 text="$(_p \
33 '%s installed package' \
34 '%s installed packages' $installed \
35 "<b>$installed</b>")"
37 [ -f "$PKGS_DB/packages.list" ] && mtime=$(find $PKGS_DB/packages.list -mtime +10;)
38 up=0; [ -f "$PKGS_DB/packages.up" ] && up=$(cat $PKGS_DB/packages.up | wc -l)
41 # Notification icon
43 listen() {
44 # Manage the I/O redirection from SHell
45 rm -f $fifo; mkfifo $fifo
47 # Attach a file descriptor
48 exec 3<> $fifo
50 # Notification icon
51 yad --notification --listen --image='TazPkg' \
52 --text="$(_ 'Checking packages lists - %s' "$text")" <&3
54 # Clean-up
55 rm -f $fifo
56 }
59 # Notification menu (right click)
61 menu() {
62 cat << EOT
63 menu:\
64 $(_n 'My packages' )!tazweb $panel?list!TazPkg|\
65 $(_n 'Recharge lists' )!tazweb $panel?recharge!tazpkg-up|\
66 $(_n 'Check upgrade' )!tazweb $panel?up!tazpkg-up|\
67 $(_n 'TazPkg SHell' )!terminal -e tazpkg shell!utilities-terminal|\
68 $(_n 'TazPkg manual' )!tazweb $doc!slitaz-doc|\
69 $(_n 'Close notification')!quit!gtk-close
70 EOT
71 }
74 case $1 in
75 usage|help|*-h)
76 _n "Usage:"; echo " $(basename $0)"
77 ;;
78 *)
79 # Sleep before displaying the notification icon and
80 # sleep to let user read the tooltips.
81 sleep 4
82 listen &
83 sleep 2
84 menu > $fifo
85 sleep 6
87 # Missing packages list
88 if [ ! -f $PKGS_DB/packages.list ]; then
89 tooltip="$(_ 'No packages list found - %s' "$text")"
90 (echo "action:tazweb $panel?recharge"
91 echo "tooltip:$tooltip"
92 echo "icon:tazpkg-up") > $fifo
93 exit 0
94 fi
96 # Too old packages list
97 if [ "$mtime" ]; then
98 tooltip="$(_ 'Your packages list is older than 10 days')"
99 (echo "action:tazweb $panel?recharge"
100 echo "tooltip:$tooltip"
101 echo "icon:tazpkg-up") > $fifo
102 exit 0
103 fi
105 # Available upgrades
106 if [ "$up" -gt 0 ]; then
107 tooltip="$(_p \
108 'There is %s upgradeable package' \
109 'There are %s upgradeable packages' $up \
110 "<b>$up</b>")"
111 (echo "action:tazweb $panel?up"
112 echo "tooltip:$tooltip"
113 echo "icon:tazpkg-up") > $fifo
114 exit 0
115 fi
117 # Nothing to do, close notification
118 tooltip="$(_ 'System is up to date - %s' "$text")"
119 echo "tooltip:$tooltip" > $fifo
120 sleep 10
121 echo "quit" > $fifo
122 ;;
123 esac
124 exit 0