X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=blobdiff_plain;f=bin%2Faway-actions;h=30ad0e4000d5e9848fa8425865275adad0dc2290;hp=c49a1dc936d8dfc225b1da9b9ac3002be9ae458c;hb=9175caecfb65e95e8c1d3df74f297a7098a35603;hpb=1b4a78d29bac00a8ead297a427a38a51a22723c0 diff --git a/bin/away-actions b/bin/away-actions index c49a1dc..30ad0e4 100755 --- a/bin/away-actions +++ b/bin/away-actions @@ -1,48 +1,95 @@ -#!/bin/sh +#!/bin/bash # $Id$ -# -*- sh -*- vim: ft=sh sw=4 sts=4 +# -*- sh -*- vim:set ft=sh sw=4 sts=4: -# Performs routine actions based on my away status. Designed to be -# periodically called by cron on homer. +# Checks several sources of information and updates my away status +# appropriately. Designed to be periodically called by away-tpope. -away="`tpope away`" -activity="`tpope activity`" -ping -c 1 marge >/dev/null 2>&1 && eval `ssh marge cat .away-smart` +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"|"Adult Swim"|"") is_away=0 ;; + Sleeping|"Away from keyboard"|TV*|"") is_away=0 ;; *[Cc]lass*) is_away=1 ;; esac -[ "$old_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 && br -F -F -elif [ -f /tmp/.tpope_lights ]; then - 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 - br -n 5 + $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 [ "$activity" ]; then - information="$activity" -elif [ "$away" ]; then - information="$away" -elif [ "$old_alive" = "lisa" ]; then - information="On laptop" -else - information= -fi - -if [ -z "$information" ]; then - echo > "$HOME/.caminfo" - echo Here > "$HOME/.status" +if [ "$information" = "On desktop" ]; then + echo > "$HOME/.caminfo.deskcam" + echo "- On desktop" > "$HOME/.caminfo.bedcam" rm -f "$HOME/.plan" else - echo "- $information" > "$HOME/.caminfo" - echo "$information" > "$HOME/.status" + 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 -ping -c 1 bart >/dev/null && scp -q "$HOME/.status" bart: 2>/dev/null -ping -c 1 abe >/dev/null && scp -q "$HOME/.status" abe: 2>/dev/null +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