tazpkg rev 556

new tazpkg-notify, use notification menu and autoclose if nothing to do
author Christophe Lincoln <pankso@slitaz.org>
date Fri Mar 02 15:10:11 2012 +0100 (2012-03-02)
parents ab830ecf3a8a
children 25bd142e8614
files tazpkg-notify tazpkg.conf
line diff
     1.1 --- a/tazpkg-notify	Fri Mar 02 11:21:19 2012 +0100
     1.2 +++ b/tazpkg-notify	Fri Mar 02 15:10:11 2012 +0100
     1.3 @@ -12,183 +12,84 @@
     1.4  # Authors : Christophe Lincoln <pankso@slitaz.org>
     1.5  #
     1.6  
     1.7 -. /etc/slitaz/tazpkg.conf
     1.8 -LOCALSTATE="/var/lib/tazpkg"
     1.9 -
    1.10 -# Include gettext helper script.
    1.11 +# I18n
    1.12  . /usr/bin/gettext.sh
    1.13 -
    1.14 -# Export package name for gettext.
    1.15  TEXTDOMAIN='tazpkg-notify'
    1.16  export TEXTDOMAIN
    1.17  
    1.18 -up=$(cat $LOCALSTATE/packages.up | wc -l)
    1.19 -rel=$(cat /etc/slitaz-release)
    1.20 +fifo=/tmp/$(basename $0).fifo
    1.21 +panel="http://tazpanel:82/pkgs.cgi"
    1.22 +db="/var/lib/tazpkg"
    1.23 +doc="/usr/share/doc/tazpkg/tazpkg.html"
    1.24 +installed=$(ls $db/installed | wc -l)
    1.25 +text="$(gettext "Installed packages") <b>$installed</b>"
    1.26 +[ -f "$db/packages.list" ] && mtime=$(find $db/packages.list -mtime +10;)
    1.27 +[ -f "$db/packages.up" ] && up=$(cat $db/packages.up | wc -l)
    1.28  
    1.29 -# Kill the notification icon after user pressed on it.
    1.30 -kill_notification() {
    1.31 -	for p in `ps | grep "yad --notification" | awk '{print $1}'`
    1.32 -	do
    1.33 -		kill -9 $p 2>/dev/null
    1.34 -	done
    1.35 +# Notification icon
    1.36 +listen() {
    1.37 +	# Manage the I/O redirection from SHell
    1.38 +	rm -f $fifo && mkfifo $fifo		
    1.39 +	# Attach a file descriptor
    1.40 +	exec 3<> $fifo	
    1.41 +	# Notification icon
    1.42 +	yad --notification --listen --image="tazpkg" \
    1.43 +		--text="Checking packages lists - $text" <&3
    1.44 +	# Clean-up
    1.45 +	rm -f $fifo
    1.46  }
    1.47  
    1.48 -# Message for up
    1.49 -up_msg() {
    1.50 -	eval_gettext "<b>There are \$up upgradeable packages for your SliTaz \$rel</b>
    1.51 -You should upgrade your system to get all the latest fixes
    1.52 -and improvements from the SliTaz contributors"
    1.53 +# Notication menu (right click)
    1.54 +menu() {
    1.55 +	cat << EOT
    1.56 +menu:\
    1.57 +$(gettext "My packages")!tazweb $panel?list!tazpkg|\
    1.58 +$(gettext "Recharge lists")!tazweb $panel?recharge!tazpkg-up|\
    1.59 +$(gettext "Check upgrade")!tazweb $panel?up!tazpkg-up|\
    1.60 +$(gettext "TazPKG SHell")!terminal -e tazpkg shell!xterm|\
    1.61 +$(gettext "TazPKG manual")!tazweb $doc!text-html|\
    1.62 +$(gettext "Close notification")!quit!gtk-close
    1.63 +EOT
    1.64  }
    1.65  
    1.66 -# Message for list older than 10 days
    1.67 -old_list_msg() {
    1.68 -	eval_gettext "<b>Your SliTaz \$rel packages list is older than 10 days</b>
    1.69 -You should recharge the list to check for updates"
    1.70 -}
    1.71 -
    1.72 -# Message if packages.list is missing
    1.73 -no_list_msg() {
    1.74 -	eval_gettext "<b>No packages list found on your SliTaz \$rel system</b>
    1.75 -You will need to recharge the list of mirrored packages
    1.76 -if you want to install packages or upgrade your system"
    1.77 -}
    1.78 -
    1.79 -#
    1.80 -# Main GUI box for up packages
    1.81 -#
    1.82 -up_main() {
    1.83 -	yad --text --width=400 \
    1.84 -		--geometry="$NOTIFY_GEOM" \
    1.85 -		--undecorated \
    1.86 -		--title="TazPKG Notification" \
    1.87 -		--image="tazpkg-up" \
    1.88 -		--image-on-top \
    1.89 -		--on-top \
    1.90 -		--text="`up_msg`" \
    1.91 -		--button="`gettext \"Upgrade:2\"`" \
    1.92 -		--button="gtk-close:1"
    1.93 -}
    1.94 -
    1.95 -# Notification icon for up packages
    1.96 -up_notify() {
    1.97 -	yad --notification \
    1.98 -		--image=tazpkg \
    1.99 -		--text="`up_msg`" \
   1.100 -		--command="tazpkg-notify upgrade"
   1.101 -}
   1.102 -
   1.103 -# Main up function
   1.104 -up() {
   1.105 -	# Store box results
   1.106 -	main=`up_main`
   1.107 -	ret=$?
   1.108 -	kill_notification
   1.109 -	# Deal with --button values
   1.110 -	case $ret in
   1.111 -		1) exit 0 ;;
   1.112 -		2) tazweb http://tazpanel:82/pkgs.cgi?up & ;;
   1.113 -		*) continue ;;
   1.114 -	esac
   1.115 -}
   1.116 -
   1.117 -#
   1.118 -# Main GUI box for missing packages.list
   1.119 -#
   1.120 -old_list_main() {
   1.121 -	yad --text --width=400 \
   1.122 -		--geometry="$NOTIFY_GEOM" \
   1.123 -		--undecorated \
   1.124 -		--title "TazPKG Notification" \
   1.125 -		--image="tazpkg-up" \
   1.126 -		--image-on-top \
   1.127 -		--on-top \
   1.128 -		--text "`old_list_msg`" \
   1.129 -		--button="`gettext \"Recharge now:2\"`" \
   1.130 -		--button="gtk-close:1"
   1.131 -}
   1.132 -
   1.133 -# Notification icon if no packages.list
   1.134 -old_list_notify() {
   1.135 -	yad --notification \
   1.136 -		--image=tazpkg \
   1.137 -		--text="`old_list_msg`" \
   1.138 -		--command="tazpkg-notify no-list"
   1.139 -}
   1.140 -
   1.141 -# Main missing packages.list function
   1.142 -old_list() {
   1.143 -	# Store box results
   1.144 -	main=$(old_list_main)
   1.145 -	ret=$?
   1.146 -	kill_notification
   1.147 -	# Deal with --button values
   1.148 -	case $ret in
   1.149 -		1) exit 0 ;;
   1.150 -		2) tazweb http://tazpanel:82/pkgs.cgi?recharge & ;;
   1.151 -		*) continue ;;
   1.152 -	esac
   1.153 -}
   1.154 -
   1.155 -#
   1.156 -# Main GUI box for missing packages.list
   1.157 -#
   1.158 -no_list_main() {
   1.159 -	yad --text --width=400 \
   1.160 -		--geometry="$NOTIFY_GEOM" \
   1.161 -		--undecorated \
   1.162 -		--show-uri \
   1.163 -		--title="TazPKG Notification" \
   1.164 -		--image="tazpkg-up" \
   1.165 -		--image-on-top \
   1.166 -		--on-top \
   1.167 -		--text "`no_list_msg`" \
   1.168 -		--button="`gettext \"Recharge now:2\"`" \
   1.169 -		--button="gtk-close:1"
   1.170 -}
   1.171 -
   1.172 -# Notification icon if no packages.list
   1.173 -no_list_notify() {
   1.174 -	yad --notification \
   1.175 -		--image=tazpkg \
   1.176 -		--text="`no_list_msg`" \
   1.177 -		--command="tazpkg-notify no-list"
   1.178 -}
   1.179 -
   1.180 -# Main missing packages.list function
   1.181 -no_list() {
   1.182 -	# Store box results
   1.183 -	main=$(no_list_main)
   1.184 -	ret=$?
   1.185 -	kill_notification
   1.186 -	# Deal with --button values
   1.187 -	case $ret in
   1.188 -		1) exit 0 ;;
   1.189 -		2) tazweb http://tazpanel:82/pkgs.cgi?recharge & ;;
   1.190 -		*) continue ;;
   1.191 -	esac
   1.192 -}
   1.193 -
   1.194 -#
   1.195 -# Script commands
   1.196 -#
   1.197 -
   1.198  case $1 in
   1.199 -	upgrade)
   1.200 -		up ;;
   1.201 -	old-list)
   1.202 -		old_list ;;
   1.203 -	no-list)
   1.204 -		no_list ;;
   1.205 +	usage|help|*-h)
   1.206 +		gettext "Usage:"; echo " $(basename $0)" ;;
   1.207  	*)
   1.208 -		# Sleep first to let tazpkg upgrade on boot finish. Check if
   1.209 -		# any upgrades, then for an old list and then if any lists at all
   1.210 -		# (live or first boot)
   1.211 +		# Sleep before displaying the notification icon and
   1.212 +		# sleep to let user read the tooltips.
   1.213 +		sleep 4
   1.214 +		listen &
   1.215 +		sleep 2
   1.216 +		menu > $fifo
   1.217 +		sleep 6
   1.218 +		# Missing packages list
   1.219 +		if [ ! -f $db/packages.list ]; then
   1.220 +			tooltip=$(eval_gettext \
   1.221 +				"No packages list found - \$text")
   1.222 +			echo "action:tazweb $panel?recharge" > $fifo
   1.223 +			echo "tooltip:$tooltip" > $fifo
   1.224 +			echo "icon:tazpkg-up" > $fifo && exit 0
   1.225 +		fi
   1.226 +		# Too old packages list
   1.227 +		if [ "$mtime" ]; then
   1.228 +			tooltip=$(gettext "Your packages list is older than 10 days")
   1.229 +			echo "action:tazweb $panel?recharge" > $fifo
   1.230 +			echo "tooltip:$tooltip" > $fifo
   1.231 +			echo "icon:tazpkg-up" > $fifo && exit 0
   1.232 +		fi
   1.233 +		# Avalaible upgrades
   1.234 +		if [ "$up" -gt 0 ]; then
   1.235 +			tooltip=$(eval_gettext \
   1.236 +				"There are <b>\$up</b> upgradeable packages")
   1.237 +			echo "action:tazweb $panel?up" > $fifo
   1.238 +			echo "tooltip:$tooltip" > $fifo
   1.239 +			echo "icon:tazpkg-up" > $fifo && exit 0
   1.240 +		fi
   1.241 +		# Nothing to do, close notification
   1.242 +		tooltip=$(eval_gettext "System is up to date - \$text")
   1.243 +		echo "tooltip:$tooltip" > $fifo
   1.244  		sleep 10
   1.245 -		[ "$up" -gt 0 ] && up_notify && exit 0
   1.246 -		mtime=$(find /var/lib/tazpkg/packages.list -mtime +10;)
   1.247 -		[ "$mtime" ] && old_list_notify && exit 0
   1.248 -		[ ! -f $LOCALSTATE/packages.list ] && no_list_notify \
   1.249 -			&& exit 0 ;;
   1.250 +		echo "quit" > $fifo ;;
   1.251  esac
   1.252 -
   1.253 -exit 0		
   1.254 +exit 0
     2.1 --- a/tazpkg.conf	Fri Mar 02 11:21:19 2012 +0100
     2.2 +++ b/tazpkg.conf	Fri Mar 02 15:10:11 2012 +0100
     2.3 @@ -6,6 +6,3 @@
     2.4  
     2.5  # Path to Tazpkg log file.
     2.6  LOG="/var/log/tazpkg.log"
     2.7 -
     2.8 -# The geometry of the desktop notification
     2.9 -NOTIFY_GEOM="360x80-0+24"