genelists.proxy.in 1.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#!/usr/bin/perl -wT
use English;
use Fcntl ':flock';

#
# Insert new version of testbed emails lists into place on operations node.
# The single argument indicates which list is being piped into the script
# from the control node. 
#
# usage: genelists.proxy [-all | -active]
#
sub usage() {
    print STDOUT "Usage: genelists.proxy [-all | -active]\n".
	"Generate the email list files after things change\n";
    exit(-1);
}

#
# Configure variables
#
my $TBOPS       = "@TBOPSEMAIL@";

my $maildir     = "/etc/mail/lists";
my $tempfile    = "$maildir/tempfile.$$";
my $alllist     = "$maildir/testbed-users";
my $activelist  = "$maildir/testbed-active-users";
my $thelist;

#
# We don't want to run this script unless its the real version.
#
if ($UID != 0) {
    die("Must be root!");
}

# un-taint path
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# Turn off line buffering on output
#
$| = 1;

45 46 47 48
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use libtestbed;

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
if (@ARGV != 1 || ($ARGV[0] ne "-all" && $ARGV[0] ne "-active")) {
    usage();
}
if ($ARGV[0] eq "-active") {
    $thelist = $activelist;
}
else {
    $thelist = $alllist;
}

#
# Take our input and write it to the temp file.
#
open(TMP, ">$tempfile") ||
    fatal("Couldn't open $tempfile\n");
while (<STDIN>) {
    print TMP $_;
}
close(TMP);
chmod(0644, $tempfile);

#
# Now overwrite the real file.
#
system("/bin/mv $tempfile $thelist") == 0 ||
    fatal("Could not move $tempfile to $thelist: $!");

exit(0);

sub fatal {
    local($msg) = $_[0];

81
    SENDMAIL($TBOPS, "genelists.proxy failure", $msg);
82 83 84
    die($msg);
}