tazpkg view tazpkg-notify @ rev 898

Module 'get': fix temp dir; module 'find-depends': faster search, add debug messages
author Aleksej Bobylev <al.bobylev@gmail.com>
date Tue Dec 29 22:00:47 2015 +0200 (2015-12-29)
parents 21ac83abe572
children 54ebb19d4cc6
line source
1 #!/bin/sh
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
3 # tazpkg-notify - part of TazPkg
4 # Notification icon for TazPkg packages
6 # Recharging pkgs list can be done automatically at boot, so notifies users
7 # if some updates are available. Also notifies users if the packages list is too
8 # old and out-of-date or if no packages list found. This script should
9 # be run by the WM autostart script or ~/.xsession and needs a systray to
10 # sit in like in LXpanel or Tint2.
12 # Copyright (C) 2012-2015 SliTaz - GNU General Public License v3.
13 # Authors: See the AUTHORS files
16 . /lib/libtaz.sh
17 . /etc/slitaz/slitaz.conf
19 # I18n
20 export TEXTDOMAIN='tazpkg'
22 fifo=/tmp/$(basename $0).fifo
23 doc="file:///usr/share/doc/tazpkg/tazpkg.html"
24 tp='http://127.0.0.1:82/user/pkgs.cgi'
26 installed=$(wc -l < "$PKGS_DB/installed.info")
27 text="$(_p \
28 '%s installed package' \
29 '%s installed packages' "$installed" \
30 "<b>$installed</b>")"
32 [ -f "$PKGS_DB/IDs" ] && mtime=$(find "$PKGS_DB/IDs" -mtime +10;)
33 up=0; [ -f "$PKGS_DB/packages.up" ] && up=$(wc -l < "$PKGS_DB/packages.up")
36 # Standard notification, if available
38 notify() {
39 if [ -n "$(which notify-send)" ]; then
40 case $2 in
41 info) icon='dialog-information'; urgency='normal';;
42 *) icon='dialog-warning'; urgency='critical';;
43 esac
44 notify-send -i $icon -u $urgency 'TazPkg' "$1" &
45 fi
46 }
49 # Notification icon
51 listen() {
52 # Manage the I/O redirection from SHell
53 rm -f $fifo; mkfifo $fifo
55 # Attach a file descriptor
56 exec 3<> $fifo
58 # Notification icon
59 tooltip="$(_ 'Checking packages lists - %s' "$text")"
60 notify "$tooltip" 'info' &
61 yad --notification --listen --image='software-update-available' --text="$tooltip" <&3
63 # Clean-up
64 rm -f $fifo
65 }
68 # Notification menu (right click)
70 menu() {
71 cat << EOT
72 menu:\
73 $(_n 'My packages' )!tazpanel pkgs#list!package-x-generic|\
74 $(_n 'Recharge lists' )!tazbox su tazpanel pkgs#recharge!system-software-update|\
75 $(_n 'Check upgrade' )!tazbox su tazpanel pkgs#up!system-software-install|\
76 $(_n 'TazPkg SHell' )!terminal -e tazpkg shell!utilities-terminal|\
77 $(_n 'TazPkg manual' )!tazweb --notoolbar $doc!slitaz-doc|\
78 $(_n 'Close notification')!quit!gtk-close
79 EOT
80 }
83 case $1 in
84 usage|help|*-h)
85 _n "Usage:"; echo " $(basename $0)"
86 ;;
87 *)
88 # Sleep before displaying the notification icon and
89 # sleep to let user read the tooltips.
90 sleep 4
91 listen &
92 sleep 2
93 menu > $fifo
94 sleep 6
96 # Missing packages list
97 if [ ! -f "$PKGS_DB/packages.info" ]; then
98 tooltip="$(_ 'No packages list found - %s' "$text")"
99 notify "$tooltip\n<a href=\"$tp?recharge\">$(_n 'Recharge lists')</a>" &
100 (echo "action:tazbox su tazpanel pkgs#recharge"
101 echo "tooltip:$tooltip"
102 echo "icon:software-update-urgent") > $fifo
103 exit 0
104 fi
106 # Too old packages list
107 if [ -n "$mtime" ]; then
108 tooltip="$(_ 'Your packages list is older than 10 days')"
109 notify "$tooltip\n<a href=\"$tp?recharge\">$(_n 'Recharge lists')</a>" &
110 (echo "action:tazbox su tazpanel pkgs#recharge"
111 echo "action:quit"
112 echo "tooltip:$tooltip"
113 echo "icon:software-update-urgent") > $fifo
114 exit 0
115 fi
117 # Available upgrades
118 if [ "$up" -gt 0 ]; then
119 tooltip="$(_p \
120 'There is %s upgradeable package' \
121 'There are %s upgradeable packages' "$up" \
122 "<b>$up</b>")"
123 notify "$tooltip\n<a href=\"$tp?up\">$(_n 'Check upgrade')</a>" &
124 (echo "action:tazbox su tazpanel pkgs#up"
125 echo "tooltip:$tooltip"
126 echo "icon:software-update-urgent") > $fifo
127 exit 0
128 fi
130 # Nothing to do, close notification
131 tooltip="$(_ 'System is up to date - %s' "$text")"
132 notify "$tooltip" 'info' &
133 echo "tooltip:$tooltip" > $fifo
134 sleep 10
135 echo "quit" > $fifo
136 ;;
137 esac
138 exit 0