tazpkg view tazpkg-notify @ rev 937

modules/get: make wget progress metter working again
Now, Busybox v. 1.26 make the difference whether it outputs progress meter to the file or to the tty (libbb/progress.c).
Bug report: http://forum.slitaz.org/topic/two-issues-with-tazpkg-934
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Jan 27 12:13:57 2017 +0200 (2017-01-27)
parents 688494ca8f5f
children 50421cb50644
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 alias notify=/usr/libexec/tazpkg-notification
25 cmd_recharge='tazbox su tazpanel pkgs#recharge'
26 cmd_up='tazbox su tazpanel pkgs#up'
28 installed=$(wc -l < "$PKGS_DB/installed.info")
29 text="$(_p \
30 '%s installed package' \
31 '%s installed packages' "$installed" \
32 "<b>$installed</b>")"
34 [ -f "$PKGS_DB/IDs" ] && mtime=$(find "$PKGS_DB/IDs" -mtime +10;)
35 up=0; [ -f "$PKGS_DB/packages.up" ] && up=$(wc -l < "$PKGS_DB/packages.up")
38 set_yad_action() {
39 echo -e "action:$1\ntooltip:$2\nicon:software-update-urgent" > $fifo
40 }
43 quit() {
44 echo "quit" > $fifo
45 # Clean-up
46 rm -f $fifo
47 exit 0
48 }
51 case $1 in
52 usage|help|*-h)
53 _n "Usage:"; echo " $(basename $0)"
54 ;;
55 *)
56 # Sleep before displaying the notification icon
57 sleep 4
58 # Manage the I/O redirection from shell
59 rm -f $fifo; mkfifo $fifo
60 # Attach a file descriptor
61 exec 3<> $fifo
62 # Notification icon
63 yad --notification --listen --image='software-update-available' <&3 &
65 # Notification menu (right click)
66 cat > $fifo << EOT
67 menu:\
68 $(_n 'My packages' )!tazpanel pkgs#list!package-x-generic|\
69 $(_n 'Recharge lists' )!$cmd_recharge!system-software-update|\
70 $(_n 'Check upgrade' )!$cmd_up!system-software-install|\
71 $(_n 'TazPkg SHell' )!terminal -e tazpkg shell!utilities-terminal|\
72 $(_n 'TazPkg manual' )!tazweb --notoolbar $doc!slitaz-doc|\
73 $(_n 'Close notification')!quit!gtk-close
74 EOT
76 # Missing packages list
77 if [ ! -f "$PKGS_DB/packages.info" ]; then
78 tooltip="$(_ 'No packages list found')"
79 set_yad_action "$cmd_recharge" "$tooltip"
80 [ "$(notify "$tooltip" '1' "$(_n 'Recharge lists')")" == '1' ] && $cmd_recharge
81 quit
82 fi
84 # Too old packages list
85 if [ -n "$mtime" ]; then
86 tooltip="$(_ 'Your packages list is older than 10 days')"
87 set_yad_action "$cmd_recharge" "$tooltip"
88 [ "$(notify "$tooltip" '1' "$(_n 'Recharge lists')")" == '1' ] && $cmd_recharge
89 quit
90 fi
92 # Available upgrades
93 if [ "$up" -gt 0 ]; then
94 tooltip="$(_p \
95 'There is %s upgradeable package' \
96 'There are %s upgradeable packages' "$up" \
97 "<b>$up</b>")"
98 set_yad_action "$cmd_up" "$tooltip"
99 [ "$(notify "$tooltip" '1' "$(_n 'Check upgrade')")" == '1' ] && $cmd_up
100 quit
101 fi
103 # Nothing to do, close notification
104 tooltip="$(_ 'System is up to date')"
105 echo "tooltip:$tooltip\n$text" > $fifo
106 answer=$(notify "$tooltip"$'\n'"$text" '0' "$(_n 'Recharge lists')" "$(_n 'Check upgrade')")
107 case "$answer" in
108 1) $cmd_recharge;;
109 2) $cmd_up;;
110 esac
111 sleep 10
112 quit
113 ;;
114 esac
115 quit