New hostnames (obsolete file)
[tpope-extra.git] / bin / away-actions
index 2ae60efaadd6e5326b738e0fcbbd31d537857213..30ad0e4000d5e9848fa8425865275adad0dc2290 100755 (executable)
@@ -5,44 +5,73 @@
 # 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`"
+br=lucille
+
+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 $br br -F -F
+    ulimit -S -u 92
+    for host in buster; 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 $br br -n 4
     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 $br br -n 4
+    ulimit -S -u 92
+#    for host in lucille; 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"
@@ -55,12 +84,12 @@ else
     echo "$information" > "$HOME/.plan"
 fi
 
-for host in bart homer sarah clancy; do
+for host in gob barry lucille buster oscar; do
     ping -c 1 $host >/dev/null && scp -q "$HOME/.status" $host: 2>/dev/null
 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
+ping -c 1 lucille >/dev/null && scp -q "$HOME/.caminfo.deskcam" lucille:.caminfo 2>/dev/null
+ping -c 1 buster >/dev/null && scp -q "$HOME/.caminfo.bedcam" buster:.caminfo 2>/dev/null
+rm -f .caminfo.deskcam .caminfo.bedcam
 
 exit 0