etchosts 1.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#
# 
#
use strict;
use libinstall;
use installvars;

sub Install($$$)
{
    my ($server, $isupdate, $impotent) = @_;

    # List of names that goes into $HOSTS and which must resolve.
    my $boss_string = "${BOSSNODE_IP}\t${BOSSNODE} boss";
    my $ops_string  = "${USERNODE_IP}\t@OPS_NAMES";
    my $fs_string;

    if ($USERNODE_IP eq $FSNODE_IP) {
Mike Hibler's avatar
Mike Hibler committed
18
	$ops_string .= " ${FSNODE} fs";
19 20
    }
    elsif ($BOSSNODE_IP eq $FSNODE_IP) {
Mike Hibler's avatar
Mike Hibler committed
21
	$boss_string .= " ${FSNODE} fs";
22 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
    }
    else {
	$fs_string = "${FSNODE_IP}\t${FSNODE} fs";
    }
    my $string = "$boss_string\n$ops_string";
    $string   .= "\n$fs_string" if (defined($fs_string));

    if ($isupdate) {
	# Look for uncommented entries for our servers.
	my @dellist = (qr(^[\d\.]+\s+\w*boss),
		       qr(^[\d\.]+\s+\w*ops),
		       qr(^[\d\.]+\s+\w*fs));

	Phase "hosts", "Updating boss/ops/fs IP addresses in $HOSTS", sub {
	    DoneIfUpdated($HOSTS, $string);
	    UpdateFileFatal($HOSTS, \@dellist, $string);
	};
    }
    else {
	Phase "hosts", "Adding boss/ops/fs IP addresses to $HOSTS", sub {
	    DoneIfEdited($HOSTS);
	    
	    # XXX get rid of any existing lines with boss/ops/fs
	    if ($ELABINELAB) {
		my $dellist = "-e '/^${BOSSNODE_IP}/d' -e '/^${USERNODE_IP}/d'";
		if (!ISFS($server)) {
		    $dellist .= " -e '/^${FSNODE_IP}/d'";
		}
		ExecQuietFatal("sed -i.orig $dellist $HOSTS");
	    }
	    BackUpFileFatal($HOSTS);
	    AppendToFileFatal($HOSTS, $string);
	};
    }
    return 0;
}

# Local Variables:
# mode:perl
# End: