htmlinstall.in 2.47 KB
Newer Older
1 2 3
#!/usr/bin/perl -w
#
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
#
use English;
use Getopt::Std;
use File::Basename;

#
# Install html files, filtering local goo (emulab.net to OURDOMAIN).
# 
sub usage {
    print STDERR "Usage: htmlinstall <src> <target>\n";
    exit(-1);
}
my $optlist  = "";

#
# Configure variables
#
my $TB		= "@prefix@";
my $WWWHOST	= "@WWWHOST@";
my $INSTALL     = "@INSTALL@ -m 444";
my $tempfile	= "/tmp/html.$$";
my $TBMAINSITE  = 1;

#
# Hardcoded check against $WWWHOST, to prevent anyone from
# accidentally setting $TBMAINSITE when it should not be
#
if ($WWWHOST ne "www.emulab.net") {
    $TBMAINSITE = 0;
}

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

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

usage()
    if (@ARGV != 2);

my $source = $ARGV[0];
my $target = $ARGV[1];

#
# Open source file and filter to temporary file, then install.
#
open(IN, $source) or
    die("$0: Could not open $source: $!\n");
open(OUT, "> $tempfile") or
    die("$0: Could not open $tempfile: $!\n");

while (<IN>) {
    s/www\.emulab\.net/www.@OURDOMAIN@/g;
    s/users\.emulab\.net/@USERNODE@/g;
    s/ops\.emulab\.net/@USERNODE@/g;
    s/boss\.emulab\.net/@BOSSNODE@/g;
    s/fs\.emulab\.net/@FSNODE@/g;
    s/(\s+[-\w]+)\.emulab\.net/$1.@OURDOMAIN@/g;
    s/testbed-ops\@emulab\.net/@TBOPSEMAIL@/g;
    if (! $TBMAINSITE) {
	s/testbed-ops\@flux\.utah\.edu/@TBOPSEMAIL@/g;
	s/\@flux\.utah\.edu/\@@OURDOMAIN@/g;
    }
    print OUT $_;
}
close(IN);
close(OUT);

system("$INSTALL $tempfile $target") == 0
    or exit($? >> 8);
exit(0);

#
# Make sure tempfile deleted.
#
END {
    my $saved_exitcode = $?;
    unlink($tempfile)
	if (-e $tempfile);
    $? = $saved_exitcode;
}