From 3caeb0117b4cdaa4cecc82f8ecf86e588b4720d5 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 16 Aug 2005 21:36:16 +0000 Subject: [PATCH] Locking and miscellaneous changes --- bin/away-actions | 79 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/bin/away-actions b/bin/away-actions index 2ae60ef..2e13665 100755 --- a/bin/away-actions +++ b/bin/away-actions @@ -5,44 +5,71 @@ # Checks several sources of information and updates my away status # appropriately. Designed to be periodically called by away-tpope. -PATH="$HOME/bin:/bin:/usr/bin" +PATH="$HOME/bin:/usr/bin:/bin" +ssh="ssh -a -x -oBatchmode=yes -oSetupTimeOut=20" +ulimit -S -u 96 -away="`tpope away`" -activity="`tpope activity`" +if [ -f /tmp/away-actions.pid ]; then + oldpid="`cat /tmp/away-actions.pid`" + if kill -0 "$oldpid"; then + sleep 20 + if [ -f /tmp/away-actions.pid ]; then + newpid="`cat /tmp/away-actions.pid`" + [ "$newpid" = "$oldpid" ] && kill "$newpid" + sleep 1 + if [ -f /tmp/away-actions.pid && "`cat /tmp/away-actions.pid`" = "$oldpid" ]; then + kill -9 "$oldpid" + rm /tmp/away-actions.pid + elif [ -f /tmp/away-actions.pid ]; then + exit 0 + fi + fi + else + rm /tmp/away-actions.pid + fi +fi + +on_exit() { + rm /tmp/away-actions.pid +} +trap on_exit EXIT + +echo "$$" >/tmp/away-actions.pid + +#away="`tpope away`" +#activity="`tpope activity`" +. "$HOME/.away-tpope" +information="$status" case "$away" in Sleeping|"Away from keyboard"|TV*|"") is_away=0 ;; *[Cc]lass*) is_away=1 ;; esac -[ "$phone" = absent ] && is_away=1 +[ "$phone" = absent -a -z "$alive" ] && is_away=1 -if [ "$is_away" = 1 ]; then - [ ! -f /tmp/.tpope_lights ] && touch /tmp/.tpope_lights && \ - $ssh homer br -F -F -elif [ -f /tmp/.tpope_lights ]; then - $ssh homer br -n 5 +find /tmp -name .tpope_lights -maxdepth 1 -mmin 60 -exec rm {} \; +if [ "$is_away" = 1 -a ! -f /tmp/.tpope_lights ]; then + touch /tmp/.tpope_lights + $ssh homer br -F -F + ulimit -S -u 92 + for host in sarah homer; do + ping -c 1 $host >/dev/null && $ssh $host tpope xssc -lock 2>/dev/null & + done +elif [ "$is_away" = 0 -a -f /tmp/.tpope_lights ]; then + $ssh homer br -n 1 rm -f /tmp/.tpope_lights - $ssh homer br -n 5 -fi - -if [ "$activity" ]; then - information="$activity" -elif [ "$away" ]; then - information="$away" -else - case "$alive" in - lisa*|abe*) information="On laptop" ;; - sarah*) information="In bed" ;; - mona*|homer*) information="On desktop" ;; - *) information="Away from keyboard?" ;; - esac + $ssh homer br -n 1 + ulimit -S -u 92 + for host in lisa; do + ping -c 1 $host >/dev/null && $ssh $host tpope unlock + done fi +ulimit -S -u 96 -if [ -z "$information" ]; then +if [ "$information" = "On desktop" ]; then echo > "$HOME/.caminfo.deskcam" echo "- On desktop" > "$HOME/.caminfo.bedcam" - #echo "On desktop" > "$HOME/.status" rm -f "$HOME/.plan" else echo "- $information" > "$HOME/.caminfo.deskcam" @@ -61,6 +88,6 @@ done ping -c 1 homer >/dev/null && scp -q "$HOME/.caminfo.deskcam" homer:.caminfo 2>/dev/null ping -c 1 sarah >/dev/null && scp -q "$HOME/.caminfo.bedcam" sarah:.caminfo 2>/dev/null -rm -f .caminfo.bedcam +rm -f .caminfo.deskcam .caminfo.bedcam exit 0 -- 2.30.2