mfs 4.5 KB
Newer Older
1 2 3 4 5 6
#
# 
#
use strict;
use libinstall;
use installvars;
7
use emutil;
8 9 10

my $MFSTARBALL	    = "tftpboot-elabinelab.tar.gz";
my $MFSURL	    = "http://www.emulab.net/downloads/$MFSTARBALL";
11
my $MFSCONSOLE      = $NODECONSOLE;
12
my $MFSDESCRIPTORS  = "$TOP_SRCDIR/install/descriptors-mfs.xml";
13
my $LOCALIZE_MFS    = "$PREFIX/sbin/localize_mfs";
14
my $ZONEINFO	    = "/usr/share/zoneinfo";
15 16 17 18 19 20 21 22 23

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

    # Replace if this script does an update for ip/domain.
    return 0
	if ($isupdate);

24 25 26 27 28 29 30 31
    # Configure can override setting it here.
    if ($MFSVERSION eq "") {
	if ($FBSD_MAJOR >= 7.2) {
	    $MFSVERSION = "72";
	}
	else {
	    $MFSVERSION = "62";
	}
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    }

    Phase "mfs", "Setting up MFSs", sub {
	my $localfile = "$TFTP_DIR/tftpboot.tar.gz";
	
	Phase "mfsfetch", "Fetching MFS tarball", sub {
	    DoneIfExists($localfile);
	    FetchFileFatal($MFSURL, $localfile);
	};
	Phase "mfsunpack", "Unpacking MFS tarball", sub {
	    DoneIfExists("$TFTP_DIR/README");
	    ExecQuietFatal("$TAR xzf $localfile -C $TFTP_DIR");
	};
	#
	# Its the generic stuff; must localize.
	#
	my $fv = $MFSVERSION;
	if (! -e "$TFTP_DIR/freebsd${fv}") {
	    $fv = "47";
	}
	my $pdir = ".";
	if (-d "$TFTP_DIR/pxeboot${fv}") {
	    $pdir = "pxeboot${fv}";
	}
Leigh B Stoller's avatar
Leigh B Stoller committed
56 57 58
	elsif (-d "$TFTP_DIR/pxeboot72") {
	    $pdir = "pxeboot72";
	}
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
	my $cons = $MFSCONSOLE;
	if (! -e "$TFTP_DIR/$pdir/pxeboot.emu-${cons}") {
	    $cons = "sio";
	}
	Phase "pxemv", "Using ${cons} version of pxeboot", sub {
	    DoneIfExists("$TFTP_DIR/pxeboot.emu");
	    ExecQuietFatal("cd $TFTP_DIR; ".
			   "$MV $pdir/pxeboot.emu-${cons} pxeboot.emu");
	};
	Phase "freemv", "Using freebsd${fv} version of admin MFS", sub {
	    DoneIfExists("$TFTP_DIR/freebsd");
	    ExecQuietFatal("cd $TFTP_DIR; $MV freebsd${fv} freebsd");
	};
	Phase "frismv", "Using frisbee${fv} version of disk load MFS", sub {
	    DoneIfExists("$TFTP_DIR/frisbee");
	    ExecQuietFatal("cd $TFTP_DIR; $MV frisbee${fv} frisbee");
	};
	#
	# Older tarballs didn't have FBSD-specific versions of newnode MFS.
	#
	if (! -e "$TFTP_DIR/freebsd.newnode") {
	    Phase "newnode", "Using freebsd${fv} version of newnode MFS", sub {
		DoneIfExists("$TFTP_DIR/freebsd.newnode");
		ExecQuietFatal("cd $TFTP_DIR; ".
			       "$MV freebsd${fv}.newnode freebsd.newnode");
	    };
	}

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
	#
	# Fix the console device in the MFSes
	#
	Phase "mfsconsole", "Setting the console for MFSes", sub {	
	    my %consmap = (
		"sio"  => "com",
		"sio2" => "com",
		"vga"  => "vid",
		"null" => "null"
	    );
	    my $consdev = $consmap{$cons} . "console";
	    foreach my $mfs ("frisbee", "freebsd", "freebsd.newnode") {
		AppendToFileFatal("$TFTP_DIR/$mfs/boot/loader.conf.orig",
				  "console=\"$consdev\"");
	    }
	};

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
	#
	# Before we localize, need to set the MFS password sitevar,
	# since localize will break otherwise.
	#
	Phase "password", "Setting up MFS password", sub {
	    my $passhash;
	    
	    my ($status, @output) =
		ExecQuiet("$PREFIX/sbin/setsitevar -c $IMAGEPASSWORDSITEVAR");
	    PhaseFail("setsitevar failed")
		if ($status);
	    if (@output) {
		chomp($output[0]);
		PhaseSkip("already set")
		    if ($output[0] ne "");
	    }

	    #
	    # Use the same password for everything.
	    #
	    if (defined($password)) {
		$passhash = PassWordHash($password);
	    }
	    else {
		#
		# Use current root password, since we know people will
		# choose reasonable root passwords.
		#
		($status,@output) =
		    ExecQuiet("egrep '^root:' /etc/master.passwd");
		PhaseFail("egrep failed")
		    if ($status);
		if (@output && $output[0] ne '' &&
		    $output[0] =~ /^root:([^:]*)/) {
		    $passhash = $1;
		}
	    }
	    PhaseFail("Could not determine image password")
		if (!defined($passhash));

	    ExecQuietFatal("$PREFIX/sbin/setsitevar ".
			   "   $IMAGEPASSWORDSITEVAR '$passhash'");
	};

148
	#
149
	# Localize the MFSs
150
	#
151 152 153 154 155 156 157
	Phase "localize", "Localizing the MFSes", sub {
	    foreach my $mfs ("frisbee", "freebsd", "freebsd.newnode") {
		Phase "$mfs", "Localizing $mfs", sub {
		    DoneIfExists("$TFTP_DIR/$mfs/boot/mfsroot.gz");
		    ExecQuietFatal("$LOCALIZE_MFS $TFTP_DIR/$mfs");
		};
	    }
158 159 160
	};

	#
Leigh B Stoller's avatar
Leigh B Stoller committed
161 162 163
	# Load the descriptors into the DB. Inside an elabinelab these are
	# already loaded, but the script will just skip over them without
	# raising an error.
164 165 166 167 168 169 170 171 172 173 174 175 176 177
	#
	Phase "descriptors", "Loading the Image and OS IDS", sub {
	    ExecQuietFatal("cd $TOP_OBJDIR/install; ".
			   "   $SUDO -u $PROTOUSER $WAP ".
			   "   perl load-descriptors $MFSDESCRIPTORS");
	};
	PhaseSucceed("done");
    };
    return 0;
}

# Local Variables:
# mode:perl
# End: