Major overhaul
[tpope-extra.git] / bin / away-actions
1 #!/bin/bash
2 # $Id$
3 # -*- sh -*- vim:set ft=sh sw=4 sts=4:
4
5 # Checks several sources of information and updates my away status
6 # appropriately.  Designed to be periodically called by away-tpope.
7
8 PATH="$HOME/bin:/bin:/usr/bin"
9
10 away="`tpope away`"
11 activity="`tpope activity`"
12
13 case "$away" in
14     Sleeping|"Away from keyboard"|TV*|"") is_away=0 ;;
15     *[Cc]lass*) is_away=1 ;;
16 esac
17
18 [ "$phone" = absent ] && is_away=1
19
20 if [ "$is_away" = 1 ]; then
21     [ ! -f /tmp/.tpope_lights ] && touch /tmp/.tpope_lights && \
22         $ssh homer br -F -F
23 elif [ -f /tmp/.tpope_lights ]; then
24     $ssh homer br -n 5
25     rm -f /tmp/.tpope_lights
26     $ssh homer br -n 5
27 fi
28
29 if [ "$activity" ]; then
30     information="$activity"
31 elif [ "$away" ]; then
32     information="$away"
33 else
34     case "$alive" in
35         lisa*|abe*) information="On laptop" ;;
36         sarah*) information="In bed" ;;
37         mona*|homer*) information="On desktop" ;;
38         *) information="Away from keyboard?" ;;
39     esac
40 fi
41
42 if [ -z "$information" ]; then
43     echo > "$HOME/.caminfo.deskcam"
44     echo "- On desktop" > "$HOME/.caminfo.bedcam"
45     #echo "On desktop" > "$HOME/.status"
46     rm -f "$HOME/.plan"
47 else
48     echo "- $information" > "$HOME/.caminfo.deskcam"
49     if [ "$information" = "In bed" ]; then
50         echo "" > "$HOME/.caminfo.bedcam"
51     else
52         echo "- $information" > "$HOME/.caminfo.bedcam"
53     fi
54     #echo "$information" > "$HOME/.status"
55     echo "$information" > "$HOME/.plan"
56 fi
57
58 for host in bart homer sarah clancy; do
59     ping -c 1 $host >/dev/null && scp -q "$HOME/.status" $host: 2>/dev/null
60 done
61
62 ping -c 1 homer >/dev/null && scp -q "$HOME/.caminfo.deskcam" homer:.caminfo 2>/dev/null
63 ping -c 1 sarah >/dev/null && scp -q "$HOME/.caminfo.bedcam" sarah:.caminfo 2>/dev/null
64 rm -f .caminfo.bedcam
65
66 exit 0