#!/bin/bash -e

echo -n "smart-aklogging: "

#if ! which inotifywait > /dev/null ; then
#    echo "inotifywait not found!" > /dev/stderr
#    exit 1
#fi

while true ; do
    #inotifywait -q -e close_write $(echo "$KRB5CCNAME" | cut -d ':' -f 2) || echo -n "!$?!"
    cc="`echo $KRB5CCNAME | cut -d ':' -f 2`"
    read < "$cc.fifo"
    #dropbox stop
    e=0
    ak="$(aklog 2>&1)" || e=$?
    echo -n "$e"
    if [ -n "$ak" ] ; then
	zwrite xavid -q -d -i "aklog-$e" -m "$ak" || echo "$ak"
    fi
    #dropbox start
done

#dnotify -C /tmp/xavidcc/ -e bash -c 'aklog ; echo -n $?'
