tazpkg annotate tazpkg-notify @ rev 712

tazpkg: backup "official" configuration files with "--newconf" anyway.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Dec 15 04:33:27 2014 +0200 (2014-12-15)
parents 1ab24812ad7e
children 0bda827841cd
rev   line source
pankso@451 1 #!/bin/sh
pankso@451 2 #
al@633 3 # TazPkg Notify - Notification icon for TazPkg packages. Recharging pkgs
paul@477 4 # list can be done automatically at boot, so notifies users if some
paul@477 5 # updates are available. Also notifies users if the packages list is too
pankso@451 6 # old and out-of-date or if no packages list found. This script should
paul@477 7 # be run by the WM autostart script or ~/.xsession and needs a systray to
paul@477 8 # sit in like in LXpanel or Tint2.
pankso@451 9 #
al@707 10 # Copyright (C) 2012-2014 SliTaz GNU/Linux - GNU GPL v2
pankso@451 11 #
pankso@451 12 # Authors : Christophe Lincoln <pankso@slitaz.org>
pankso@451 13 #
pankso@451 14
al@710 15 . /lib/libtaz.sh
al@710 16 . /etc/slitaz/slitaz.conf
al@710 17
pankso@556 18 # I18n
al@633 19 export TEXTDOMAIN='tazpkg'
al@710 20 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
al@710 21 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
al@710 22 _p() {
al@710 23 local S="$1" P="$2" N="$3"; shift; shift; shift;
al@710 24 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
al@710 25
pankso@451 26
pankso@556 27 fifo=/tmp/$(basename $0).fifo
pankso@556 28 panel="http://tazpanel:82/pkgs.cgi"
mojo@577 29 doc="file:///usr/share/doc/tazpkg/tazpkg.html"
al@633 30
al@710 31 installed=$(wc -l < $PKGS_DB/installed.info)
al@707 32 text="$(_p \
al@707 33 '%s installed package' \
al@707 34 '%s installed packages' $installed \
al@707 35 "<b>$installed</b>")"
al@710 36
al@710 37 [ -f "$PKGS_DB/packages.list" ] && mtime=$(find $PKGS_DB/packages.list -mtime +10;)
al@710 38 up=0; [ -f "$PKGS_DB/packages.up" ] && up=$(cat $PKGS_DB/packages.up | wc -l)
pankso@451 39
al@707 40
pankso@556 41 # Notification icon
al@707 42
pankso@556 43 listen() {
pankso@556 44 # Manage the I/O redirection from SHell
al@710 45 rm -f $fifo; mkfifo $fifo
al@710 46
pankso@556 47 # Attach a file descriptor
al@603 48 exec 3<> $fifo
al@710 49
pankso@556 50 # Notification icon
al@710 51 yad --notification --listen --image='TazPkg' \
al@710 52 --text="$(_ 'Checking packages lists - %s' "$text")" <&3
al@710 53
pankso@556 54 # Clean-up
pankso@556 55 rm -f $fifo
pankso@451 56 }
pankso@451 57
al@707 58
paul@662 59 # Notification menu (right click)
al@707 60
pankso@556 61 menu() {
pankso@556 62 cat << EOT
pankso@556 63 menu:\
al@710 64 $(_n 'My packages' )!tazweb $panel?list!TazPkg|\
al@710 65 $(_n 'Recharge lists' )!tazweb $panel?recharge!tazpkg-up|\
al@710 66 $(_n 'Check upgrade' )!tazweb $panel?up!tazpkg-up|\
al@710 67 $(_n 'TazPkg SHell' )!terminal -e tazpkg shell!utilities-terminal|\
al@710 68 $(_n 'TazPkg manual' )!tazweb $doc!slitaz-doc|\
al@710 69 $(_n 'Close notification')!quit!gtk-close
pankso@556 70 EOT
pankso@451 71 }
pankso@451 72
al@707 73
pankso@451 74 case $1 in
pankso@556 75 usage|help|*-h)
al@710 76 _n "Usage:"; echo " $(basename $0)"
al@707 77 ;;
pankso@451 78 *)
pankso@556 79 # Sleep before displaying the notification icon and
pankso@556 80 # sleep to let user read the tooltips.
pankso@556 81 sleep 4
pankso@556 82 listen &
pankso@556 83 sleep 2
pankso@556 84 menu > $fifo
pankso@556 85 sleep 6
al@710 86
pankso@556 87 # Missing packages list
al@710 88 if [ ! -f $PKGS_DB/packages.list ]; then
al@710 89 tooltip="$(_ 'No packages list found - %s' "$text")"
al@710 90 (echo "action:tazweb $panel?recharge"
al@710 91 echo "tooltip:$tooltip"
al@710 92 echo "icon:tazpkg-up") > $fifo
al@707 93 exit 0
pankso@556 94 fi
al@710 95
pankso@556 96 # Too old packages list
pankso@556 97 if [ "$mtime" ]; then
al@707 98 tooltip="$(_ 'Your packages list is older than 10 days')"
al@710 99 (echo "action:tazweb $panel?recharge"
al@710 100 echo "tooltip:$tooltip"
al@710 101 echo "icon:tazpkg-up") > $fifo
al@707 102 exit 0
pankso@556 103 fi
al@710 104
paul@579 105 # Available upgrades
pankso@556 106 if [ "$up" -gt 0 ]; then
al@707 107 tooltip="$(_p \
al@707 108 'There is %s upgradeable package' \
al@707 109 'There are %s upgradeable packages' $up \
al@707 110 "<b>$up</b>")"
al@710 111 (echo "action:tazweb $panel?up"
al@710 112 echo "tooltip:$tooltip"
al@710 113 echo "icon:tazpkg-up") > $fifo
al@707 114 exit 0
pankso@556 115 fi
al@710 116
pankso@556 117 # Nothing to do, close notification
al@710 118 tooltip="$(_ 'System is up to date - %s' "$text")"
pankso@556 119 echo "tooltip:$tooltip" > $fifo
pankso@471 120 sleep 10
al@707 121 echo "quit" > $fifo
al@707 122 ;;
pankso@451 123 esac
pankso@556 124 exit 0