tazpkg view tazpkg-notify @ rev 811

Update documentation (attempt to describe all the commands both with all options). Strongly need to review and update translations and docs! Add TazPkg help system for commandline (based on the HTML docs). Attempt to drop all package lists but "packages.info". Small improvements and code prettify.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Jun 04 00:15:13 2015 +0300 (2015-06-04)
parents 0bda827841cd
children a02e36d44d06
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 tazweb="tazweb --notoolbar"
29 panelbase="http://tazpanel:82/pkgs.cgi"
30 panel="http://tazpanel:82/user/pkgs.cgi"
31 doc="file:///usr/share/doc/tazpkg/tazpkg.html"
33 installed=$(wc -l < $PKGS_DB/installed.info)
34 text="$(_p \
35 '%s installed package' \
36 '%s installed packages' $installed \
37 "<b>$installed</b>")"
39 [ -f "$PKGS_DB/packages.list" ] && mtime=$(find $PKGS_DB/packages.list -mtime +10;)
40 up=0; [ -f "$PKGS_DB/packages.up" ] && up=$(cat $PKGS_DB/packages.up | wc -l)
43 # Notification icon
45 listen() {
46 # Manage the I/O redirection from SHell
47 rm -f $fifo; mkfifo $fifo
49 # Attach a file descriptor
50 exec 3<> $fifo
52 # Notification icon
53 yad --notification --listen --image='TazPkg' \
54 --text="$(_ 'Checking packages lists - %s' "$text")" <&3
56 # Clean-up
57 rm -f $fifo
58 }
61 # Notification menu (right click)
63 menu() {
64 cat << EOT
65 menu:\
66 $(_n 'My packages' )!$tazweb $panelbase?list!TazPkg|\
67 $(_n 'Recharge lists' )!$tazweb $panel?recharge!tazpkg-up|\
68 $(_n 'Check upgrade' )!$tazweb $panel?up!tazpkg-up|\
69 $(_n 'TazPkg SHell' )!terminal -e tazpkg shell!utilities-terminal|\
70 $(_n 'TazPkg manual' )!$tazweb $doc!slitaz-doc|\
71 $(_n 'Close notification')!quit!gtk-close
72 EOT
73 }
76 case $1 in
77 usage|help|*-h)
78 _n "Usage:"; echo " $(basename $0)"
79 ;;
80 *)
81 # Sleep before displaying the notification icon and
82 # sleep to let user read the tooltips.
83 sleep 4
84 listen &
85 sleep 2
86 menu > $fifo
87 sleep 6
89 # Missing packages list
90 if [ ! -f $PKGS_DB/packages.list ]; then
91 tooltip="$(_ 'No packages list found - %s' "$text")"
92 (echo "action:$tazweb $panel?recharge"
93 echo "tooltip:$tooltip"
94 echo "icon:tazpkg-up") > $fifo
95 exit 0
96 fi
98 # Too old packages list
99 if [ "$mtime" ]; then
100 tooltip="$(_ 'Your packages list is older than 10 days')"
101 (echo "action:$tazweb $panel?recharge"
102 echo "tooltip:$tooltip"
103 echo "icon:tazpkg-up") > $fifo
104 exit 0
105 fi
107 # Available upgrades
108 if [ "$up" -gt 0 ]; then
109 tooltip="$(_p \
110 'There is %s upgradeable package' \
111 'There are %s upgradeable packages' $up \
112 "<b>$up</b>")"
113 (echo "action:$tazweb $panel?up"
114 echo "tooltip:$tooltip"
115 echo "icon:tazpkg-up") > $fifo
116 exit 0
117 fi
119 # Nothing to do, close notification
120 tooltip="$(_ 'System is up to date - %s' "$text")"
121 echo "tooltip:$tooltip" > $fifo
122 sleep 10
123 echo "quit" > $fifo
124 ;;
125 esac
126 exit 0