# # # use strict; use libinstall; use installvars; use emutil; my $MFSTARBALL = ($ELABINELAB ? "tftpboot-elabinelab.tar.gz" : "tftpboot-latest.tar.gz"); my $MFSURL = "http://www.emulab.net/downloads/$MFSTARBALL"; my $MFSCONSOLE = $NODECONSOLE; my $MFSDESCRIPTORS = "$TOP_SRCDIR/install/descriptors-mfs.xml"; my $LOCALIZE_MFS = "$PREFIX/sbin/localize_mfs"; my $ZONEINFO = "/usr/share/zoneinfo"; sub Install($$$) { my ($server, $isupdate, $impotent) = @_; # # Configure can override setting it here. # # XXX defaulting this based on the OS running on the boss node is sketchy. # It should really be based on the LCD of the experiment nodes. Quite # likely, multiple MFSes will be needed as newer HW will not be supported # by older MFSes and vice versa. # if ($MFSVERSION eq "") { if ($FBSD_MAJOR > 8 || ($FBSD_MAJOR == 8 && $FBSD_MINOR >= 2)) { if ($FBSD_ARCH eq "amd64") { $MFSVERSION = "8-64"; } else { $MFSVERSION = "82"; } } elsif ($FBSD_MAJOR > 7 || $FBSD_MAJOR == 7 && $FBSD_MINOR >= 2) { $MFSVERSION = "72"; } else { $MFSVERSION = "62"; } } if ($MFSVERSION eq "62" || $MFSVERSION eq "47") { $MFSTARBALL = "tftpboot-legacy.tar.gz"; $MFSURL = "http://www.emulab.net/downloads/$MFSTARBALL"; } # # Want to recreate the directory and start over. # if ($isupdate) { Phase "tftpboot_rename", "Backing up $TFTP_DIR", sub { DoneIfDoesntExist($TFTP_DIR); BackupDirectoryFatal($TFTP_DIR); ExecQuietFatal("/bin/rm -rf $TFTP_DIR") if (!$impotent); }; Phase "tftpboot_recreate", "Recreating $TFTP_DIR", sub { DoneIfExists($TFTP_DIR); mkdir $TFTP_DIR,0775 or PhaseFail("Unable to create $TFTP_DIR : $!"); ExecQuietFatal("$CHGRP tbadmin $TFTP_DIR"); }; } 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}"; } elsif (-d "$TFTP_DIR/pxeboot72") { $pdir = "pxeboot72"; } my $cons = $MFSCONSOLE; if (! -e "$TFTP_DIR/$pdir/pxeboot.emu-${cons}") { $cons = "sio"; } Phase "pxemv", "Using ${cons} version of $pdir", sub { DoneIfExists("$TFTP_DIR/pxeboot.emu"); ExecQuietFatal("cd $TFTP_DIR; ". "$CP -p $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"); # use the FreeBSD 9.x kernel if available if (-x "$TFTP_DIR/freebsd/boot/kernel9") { ExecQuietFatal("cd $TFTP_DIR/freebsd/boot; ". "cp -fp kernel9 kernel"); } }; Phase "frismv", "Using frisbee${fv} version of disk load MFS", sub { DoneIfExists("$TFTP_DIR/frisbee"); ExecQuietFatal("cd $TFTP_DIR; $MV frisbee${fv} frisbee"); # use the FreeBSD 9.x kernel if available if (-x "$TFTP_DIR/frisbee/boot/kernel9") { ExecQuietFatal("cd $TFTP_DIR/frisbee/boot; ". "cp -fp kernel9 kernel"); } }; # # 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"); # use the FreeBSD 9.x kernel if available if (-x "$TFTP_DIR/freebsd.newnode/boot/kernel9") { ExecQuietFatal("cd $TFTP_DIR/freebsd.newnode/boot; ". "cp -fp kernel9 kernel"); } }; } # # Before we localize, need to set the MFS password sitevar, # since localize will break otherwise. # Phase "password", "Setting up MFS password", sub { my $passhash; # Skip in update mode. PhaseSkip("update mode") if ($isupdate); 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'"); }; # # Localize the MFSs # # This opt says to include igb cruft. Needed on G8s. # my $opt = ($PROTOGENI_GENIRACK ? "-i" : ""); 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 $opt $TFTP_DIR/$mfs"); }; } }; # # 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. # if (!$isupdate) { 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: