tazpkg annotate tazpkg-notify @ rev 893

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