New hostnames
authorTim Pope <code@tpope.net>
Tue, 28 Feb 2006 20:00:03 +0000 (20:00 +0000)
committerTim Pope <code@tpope.net>
Tue, 28 Feb 2006 20:00:03 +0000 (20:00 +0000)
perl/away-tpope

index 38ce70d978bd7af59bea4ff4483395d6f5cf9577..c5bf12ce6ccc7dab9db02b89f79da044b858058e 100755 (executable)
@@ -4,7 +4,7 @@
 
 use strict;
 use vars qw(%state @ssh $last $pipe $arg $slow);
-@ssh=("ssh","-a","-x","-oBatchmode=yes","-oSetupTimeOut=20");
+@ssh=("ssh","-a","-x","-oBatchmode=yes","-oSetupTimeOut=20","-qq");
 $pipe = "/tmp/.away-tpope";
 
 $arg=shift || "";
@@ -107,6 +107,7 @@ sub cycle {
        do_phone();
        $slow=0;
     }
+    eval_chat();
     do_schedule();
     do_decision();
     save();
@@ -138,13 +139,16 @@ sub do_schedule {
        next unless /(\d\d):(\d\d)-(\d\d):(\d\d) (.*)/;
        my ($hs,$ms,$he,$me,$ev) = ($1, $2, $3, $4, $5);
        $ev =~ s/ *\[.*$//;
-       $begin = $hs*60+$ms-25;
+       $begin = $hs*60+$ms-10;
        $maxend = $he*60+$me+10;
-       $end = ($begin+25)*3/4+($maxend-10)/4;
+       $end = ($begin+10)*3/4+($maxend-10)/4;
        if($begin <= $now && $now < $end) {
            $state{'class'} = $ev;
+           internal_out("School");
            $familiar = 1;
            last;
+       } elsif($begin-35<=$now && $now<$end && $state{'phone'} eq "absent") {
+           internal_out("School");
        } elsif (($state{'class'}||'') eq $ev) {
            $familiar = 1;
            undef $state{'class'}
@@ -154,7 +158,6 @@ sub do_schedule {
     close(SCHEDULE);
     undef $state{'class'} unless ($familiar);
 
-
     open(SCHEDULE, "today --category='!school !private'|");
     $familiar = 0;
     while(<SCHEDULE>) {
@@ -191,8 +194,18 @@ sub do_chat {
     }
 }
 
+sub eval_chat {
+    if(($state{'chat'}||'') eq "jmwaller") {
+       internal_out("Work",3*60*60);
+    } elsif(($state{'chat'}||'') =~ /^tpope-\d+$/) {
+       internal_out("Work",3*60*60);
+    } elsif(($state{'chat'}||'') eq "accd") {
+       #internal_out("School",30*60);
+    }
+}
+
 sub do_hosts {
-    my (@check) = ("mona", "lisa", "homer", "sarah");
+    my (@check) = ("tobias", "lucille", "lindsay", "buster");
     my (@uphosts, @livehosts, $host, $hostlist);
     if(($_[0] || 0) == 1) {
        $hostlist=$state{'hosts'};
@@ -232,7 +245,7 @@ sub is_alive {
     eval {
        local $SIG{ALRM} = sub { die "alarm\n" };
        alarm(30);
-       $ret=!(system(@ssh,shift, 'if pidof xscreensaver >/dev/null && DISPLAY=:0.0 xscreensaver-command -version >/dev/null 2>&1; then if DISPLAY=:0.0 xscreensaver-command -time 2>&1 |egrep "non-blanked|no saver status" >/dev/null; then true; else pid=`ps ax|egrep "[0-9]:[0-9][0-9] ssh marge .*(screen.*RR irc|Chat)"|sed -e "s/^  *//"|cut -d" " -f 1`; [ -f "$HOME/.irc.lock" -o -z "$pid" ] || kill $pid; false; fi; else false; fi') >> 8);
+       $ret=!(system(@ssh,shift, 'if pidof xscreensaver >/dev/null && DISPLAY=:0.0 xscreensaver-command -version >/dev/null 2>&1; then if DISPLAY=:0.0 xscreensaver-command -time 2>&1 |egrep "non-blanked|no saver status" >/dev/null; then true; else pid=`ps ax|egrep "[0-9]:[0-9][0-9] ssh michael .*(screen.*RR irc|Chat)"|sed -e "s/^  *//"|cut -d" " -f 1`; [ -f "$HOME/.irc.lock" -o -z "$pid" ] || kill $pid; false; fi; else false; fi') >> 8);
        alarm(0);
     };
     if($@) {
@@ -244,10 +257,10 @@ sub is_alive {
 
 sub do_phone {
     my $phone;
-    if(!ping('mona')) {
+    if(!ping('tobias')) {
        $phone="unknown";
     } else {
-       my $last_slh=`@ssh mona cat .blue/last_slh 2>/dev/null`;
+       my $last_slh=`@ssh tobias cat .blue/last_slh 2>/dev/null`;
        if(!$last_slh) {
            $phone="unknown";
        } elsif (time-$last_slh < 540) {
@@ -256,14 +269,15 @@ sub do_phone {
            $phone="absent";
        }
     }
-    if($state{'phone'} ne 'present' && $phone eq 'present') {
+    if(($state{'phone'}||"") ne 'present' && $phone eq 'present') {
        custom_out("");
+       internal_out("");
     }
     $state{'phone'} = $phone;
 }
 
 sub do_power {
-    open TMP, "upsc milhouse\@localhost|";
+    open TMP, "upsc milhouse\@localhost 2>/dev/null|";
     my $ups='';
     while(<TMP>) {
        chomp;
@@ -280,9 +294,11 @@ sub do_decision {
        if ($state{'customawayexp'} && $state{'customawayexp'}<time);
     custom_out("")
        if ($state{'customoutexp'} && $state{'customoutexp'}<time);
+    internal_out("")
+       if ($state{'internaloutexp'} && $state{'internaloutexp'}<time);
     custom_activity("")
        if ($state{'customactivityexp'} && $state{'customactivityexp'}<time);
-    if ($state{'customactivity'}) {
+    if (exists($state{'customactivity'})) {
        $state{'activity'}=$state{'customactivity'};
     } elsif ($state{'ups'} eq 'OB' || $state{'ups'} eq 'LB') {
        $state{'activity'}="Power outage";
@@ -297,13 +313,15 @@ sub do_decision {
        $state{'away'}=$state{'schedule'};
     } elsif ($state{'phone'} ne 'present' && $state{'class'}) {
        $state{'away'}="Class: ".$state{'class'};
+    } elsif ($state{'internalout'} && $state{'phone'} eq 'absent') {
+       $state{'away'}=$state{'internalout'};
     } elsif ($state{'alive'}) {
        undef($state{'away'});
     } elsif ($state{'phone'} eq 'absent') {
        $state{'away'}="Out";
     } elsif ($state{'phone'} ne 'absent') {
        my @now=localtime;
-       if (1 <= $now[2] && $now[2] < 9) {
+       if (0 <= $now[2] && $now[2] < 7) {
            $state{'away'}="Sleeping";
        } else {
            $state{'away'}="Away from keyboard";
@@ -362,6 +380,18 @@ sub custom_out {
     save();
 }
 
+sub internal_out {
+    if($_[0]) {
+       $state{'internalout'} = $_[0];
+       $state{'internaloutexp'} = time+($_[1]||150*60);
+    } else {
+       undef $state{'internalout'};
+       undef $state{'internaloutexp'};
+    }
+    do_decision();
+    save();
+}
+
 sub custom_activity {
     if($_[0]) {
        $state{'customactivity'} = $_[0];
@@ -379,11 +409,11 @@ sub save {
        $state{'status'}=$state{'activity'};
     } elsif (defined($state{'away'})) {
        $state{'status'}=$state{'away'};
-    } elsif ($state{'alive'} eq "mona" || $state{'alive'} eq "homer") {
+    } elsif ($state{'alive'} eq "tobias" || $state{'alive'} eq "lucille") {
        $state{'status'}="On desktop";
-    } elsif ($state{'alive'} eq "lisa") {
+    } elsif ($state{'alive'} eq "lindsay") {
        $state{'status'}="On laptop";
-    } elsif ($state{'alive'} eq "sarah") {
+    } elsif ($state{'alive'} eq "buster") {
        $state{'status'}="In bed";
     }
     open CONF, '>' . $ENV{'HOME'} . "/.away-tpope" || die $!;
@@ -416,6 +446,10 @@ sub save {
 
 sub load {
     open CONF, '<' . $ENV{'HOME'} . "/.away-tpope" or return;
+    undef $state{'customactivity'};
+    undef $state{'customaway'};
+    undef $state{'customout'};
+    undef $state{'internalout'};
     while(my $line=<CONF>) {
        $line =~ s/\\n/\n/g;
        $line =~ s/\\"/"/g;