tazpkg annotate tazpkg-notify @ rev 947

modules/get: get_pkg_cookmode(): file may be absent.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Jun 05 22:36:04 2017 +0300 (2017-06-05)
parents 54ebb19d4cc6
children 9d683c983e2e
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
paul@943 6 # Recharging pkgs list can be done automatically at boot, so notify users
paul@943 7 # if some updates are available. Also notify 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@899 24 alias notify=/usr/libexec/tazpkg-notification
al@899 25 cmd_recharge='tazbox su tazpanel pkgs#recharge'
al@899 26 cmd_up='tazbox su tazpanel pkgs#up'
al@633 27
al@840 28 installed=$(wc -l < "$PKGS_DB/installed.info")
al@707 29 text="$(_p \
al@707 30 '%s installed package' \
al@840 31 '%s installed packages' "$installed" \
al@707 32 "<b>$installed</b>")"
al@710 33
al@840 34 [ -f "$PKGS_DB/IDs" ] && mtime=$(find "$PKGS_DB/IDs" -mtime +10;)
al@840 35 up=0; [ -f "$PKGS_DB/packages.up" ] && up=$(wc -l < "$PKGS_DB/packages.up")
pankso@451 36
al@707 37
al@899 38 set_yad_action() {
al@899 39 echo -e "action:$1\ntooltip:$2\nicon:software-update-urgent" > $fifo
al@870 40 }
al@870 41
al@870 42
al@899 43 quit() {
al@899 44 echo "quit" > $fifo
pankso@556 45 # Clean-up
pankso@556 46 rm -f $fifo
al@899 47 exit 0
pankso@451 48 }
pankso@451 49
al@707 50
pankso@451 51 case $1 in
pankso@556 52 usage|help|*-h)
al@710 53 _n "Usage:"; echo " $(basename $0)"
al@707 54 ;;
pankso@451 55 *)
al@899 56 # Sleep before displaying the notification icon
pankso@556 57 sleep 4
al@899 58 # Manage the I/O redirection from shell
al@899 59 rm -f $fifo; mkfifo $fifo
al@899 60 # Attach a file descriptor
al@899 61 exec 3<> $fifo
al@899 62 # Notification icon
al@899 63 yad --notification --listen --image='software-update-available' <&3 &
al@899 64
al@899 65 # Notification menu (right click)
al@899 66 cat > $fifo << EOT
al@899 67 menu:\
al@899 68 $(_n 'My packages' )!tazpanel pkgs#list!package-x-generic|\
al@899 69 $(_n 'Recharge lists' )!$cmd_recharge!system-software-update|\
al@899 70 $(_n 'Check upgrade' )!$cmd_up!system-software-install|\
al@899 71 $(_n 'TazPkg SHell' )!terminal -e tazpkg shell!utilities-terminal|\
al@899 72 $(_n 'TazPkg manual' )!tazweb --notoolbar $doc!slitaz-doc|\
al@899 73 $(_n 'Close notification')!quit!gtk-close
al@899 74 EOT
al@710 75
pankso@556 76 # Missing packages list
al@840 77 if [ ! -f "$PKGS_DB/packages.info" ]; then
al@899 78 tooltip="$(_ 'No packages list found')"
al@899 79 set_yad_action "$cmd_recharge" "$tooltip"
al@899 80 [ "$(notify "$tooltip" '1' "$(_n 'Recharge lists')")" == '1' ] && $cmd_recharge
al@899 81 quit
pankso@556 82 fi
al@710 83
pankso@556 84 # Too old packages list
al@840 85 if [ -n "$mtime" ]; then
al@707 86 tooltip="$(_ 'Your packages list is older than 10 days')"
al@899 87 set_yad_action "$cmd_recharge" "$tooltip"
al@899 88 [ "$(notify "$tooltip" '1' "$(_n 'Recharge lists')")" == '1' ] && $cmd_recharge
al@899 89 quit
pankso@556 90 fi
al@710 91
paul@579 92 # Available upgrades
pankso@556 93 if [ "$up" -gt 0 ]; then
al@707 94 tooltip="$(_p \
al@707 95 'There is %s upgradeable package' \
al@840 96 'There are %s upgradeable packages' "$up" \
al@707 97 "<b>$up</b>")"
al@899 98 set_yad_action "$cmd_up" "$tooltip"
al@899 99 [ "$(notify "$tooltip" '1' "$(_n 'Check upgrade')")" == '1' ] && $cmd_up
al@899 100 quit
pankso@556 101 fi
al@710 102
pankso@556 103 # Nothing to do, close notification
al@899 104 tooltip="$(_ 'System is up to date')"
al@899 105 echo "tooltip:$tooltip\n$text" > $fifo
al@899 106 answer=$(notify "$tooltip"$'\n'"$text" '0' "$(_n 'Recharge lists')" "$(_n 'Check upgrade')")
al@899 107 case "$answer" in
al@899 108 1) $cmd_recharge;;
al@899 109 2) $cmd_up;;
al@899 110 esac
pankso@471 111 sleep 10
al@899 112 quit
al@707 113 ;;
pankso@451 114 esac
al@899 115 quit