#!/bin/bash # $Id$ # -*- sh -*- vim:set ft=sh sw=4 sts=4: # Checks several sources of information and updates my away status # appropriately. Designed to be periodically called by away-tpope. PATH="$HOME/bin:/usr/bin:/bin" ssh="ssh -a -x -oBatchmode=yes -oSetupTimeOut=20" ulimit -S -u 96 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 -a -z "$alive" ] && is_away=1 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 $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 [ "$information" = "On desktop" ]; then echo > "$HOME/.caminfo.deskcam" echo "- On desktop" > "$HOME/.caminfo.bedcam" rm -f "$HOME/.plan" else echo "- $information" > "$HOME/.caminfo.deskcam" if [ "$information" = "In bed" ]; then echo "" > "$HOME/.caminfo.bedcam" else echo "- $information" > "$HOME/.caminfo.bedcam" fi #echo "$information" > "$HOME/.status" echo "$information" > "$HOME/.plan" fi 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 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