#!/usr/local/bin/perl # sub Usage { print <" where username is your username. USAGE exit 1; } # ---------------------------------------- # # uses the rptp command-line interface # Justin Mason 20/12/93. $RPTP_PATH = "/usr/local/bin"; # Where rptp(1) can be found # default values (in rplay(1) terms) $vol = 40; $pri = 0; # if someone has a display on these hosts, map it to somewhere # else that has an rplayd daemon. %mappings = ( "operation", "class", "stream", "class", "exception", "class" ); # you probably won't need to change this. $ENV{'PATH'} = "$RPTP_PATH:/usr/ucb:/usr/local/bin" . $ENV{'PATH'}; # end of config section ---------------------------- require 'newgetopt.pl'; &NGetOpt("user:s") || &Usage; &main; while (<>) { ; } # eat the input exit 0; sub gethost { $host = $DEFAULTHOST; $smallest = 9999; if ($opt_user eq '') { $home = $ENV{'HOME'} || $ENV{'LOGDIR'} || (getpwuid($<))[7] || die "You have no \$HOME!\n"; $user = $ENV{'USER'} || getlogin || (getpwuid($<))[0] || "someone"; } else { $user = $opt_user; $home = (getpwnam ($user))[7] || die "$user has no password entry!"; } if (-r "$home/.display") { open (H, "< $home/.display"); chop ($host = ); close H; } else { # assume that the least idle is on the user's display (er ;) open (RWHO, "rwho |"); while () { next unless /^${user}\s/; # username next unless ($' =~ /^\s+([^:]+):/); # hostname $h = $1; next unless /[A-Z][a-z][a-z] [ \d]\d \d\d:\d\d/; # date $_ = $'; # get the idle, if it exists if ($_ =~ /:/) { ($host = $h) if (($`*60 + $') < $smallest); } else { # not idle $host = $h; } } close RWHO; } $host; } sub main { $host = &gethost; if (-r "$home/.mailnoise") { open (N, "< $home/.mailnoise"); while () { tr/A-Z/a-z/; chop; s/^\s+//g; /^priority: / && ($pri = $'); /^host: / && ($host = $'); /^volume: / && ($vol = $'); /^noise: / && ($noise .= " $'"); } close N; } $noise =~ s/^ //; open (RPTP, "echo find \"$noise\" \| rptp 2>&1 |"); while () { /^$noise/ && $valid++; } close RPTP; if ($valid) { if ($host eq '') { # print STDERR "rplay -v $vol -P $pri ", $noise; system ("/usr/local/bin/rplay", "-v", $vol, "-P", $pri, $noise); } else { # print STDERR "rplay -h $host -v $vol -P $pri ", $noise; system ("/usr/local/bin/rplay", "-h", $host, "-v", $vol, "-P", $pri, $noise); } } }