rc.mkelab 108 KB
Newer Older
1 2
#!/usr/bin/perl -w
#
3
# Copyright (c) 2004-2014 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
#
# XXX I hardwire IPs into generated /etc/rc.conf and /etc/rc.resolv.
#
# TODO:
#  * Put admin people in local homedirs. 
#
#
use English;
use Getopt::Std;
use Socket;
use IO::Handle;

35 36 37
# XXX not yet complete
my $domirror = 0;

38 39 40 41 42 43
sub usage()
{
    print "Usage: " .
	scriptname() . " boot|shutdown|reconfig|reset\n";
    exit(1);
}
44
my $optlist = "dsj";
45 46
my $action  = "boot";
my $debug   = 0;
47
my $skipit  = 1;	# Temporary until images updated.
48
my $opsjail = 0;	# Only for ops; running inside a jail.
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

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

# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }

# Only root.
if ($EUID != 0) {
    die("*** $0:\n".
	"    Must be root to run this script!\n");
}

# Script specific goo. Put it someplace where prepare script will leave it.
my $LOGFILE    = "/usr/mkelab.debug";
my %elabconfig = ();

#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself. 
# 
use libsetup;
use liblocsetup;
use libtmcc;
use librc;

#
# Not all clients support this.
#
exit(0)
David Johnson's avatar
David Johnson committed
79
    if (REMOTE() || JAILED() || DELAYHOST());
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

# Protos.
sub doboot();
sub doshutdown();
sub doreconfig();
sub docleanup();

# Parse command line.
if (! getopts($optlist, \%options)) {
    usage();
}
if (defined($options{'d'})) {
    $debug = 1;
}
if (defined($options{'s'})) {
    $skipit = 1;
}
97 98 99
if (defined($options{'j'})) {
    $opsjail = 1;
}
100 101 102 103 104 105 106
# Allow default above.
if (@ARGV) {
    $action = $ARGV[0];
}

# More stuff we need below.
my $domain;
107
my ($pid,$eid,$vid) = check_nickname();
108 109 110 111 112 113
my $file    = TMCREATOR();
my $creator = `cat $file`;
chomp($creator);

my $hostname = `hostname`;
chomp($hostname);
114
my ($bossname, $outer_bossip) = tmccbossinfo();
115

116 117 118 119
# This is the router IP to the outside world. Needed in lots of places.
my $outer_routerip;
# And the netmask on the outer control network.
my $outer_netmask;
120 121
# And the control interface
my $outer_controlif;
122

Leigh B. Stoller's avatar
Leigh B. Stoller committed
123 124 125
# Outer FS node name. See below.
my $fsname;

126 127
# Cert stuff to give the inner emulab
my $RPCCERT = "/usr/testbed/etc/outer_emulab.pem";
128
#my $RPCPORT = 7778;
129

130 131 132 133 134 135 136 137
#
# Elab daemons to kill off before setting up boss/ops/fs.
# Order matters: must kill event agents before evproxy and pubsubd.
# XXX we leave slothd running for idleswap in case we hang.
#
my @DAEMONS = ("emulab-watchdog", "progagent", "linktest",
	       "syncd", "evproxy", "pubsubd");

138 139 140 141 142 143
#
# Standard system daemons to kill off before we run the Emulab cleanup script.
#
my @SYSDAEMONS = ("cron", "mountd", "ntpd", "sendmail",
		  "syslogd", "nfsd", "rpcbind");

144 145
# or this...
my $FSMOUNTDIR = "/q";
146 147 148 149
my $OPSMOUNTDIR = "/ops";

# Hardwired?
my $TBDIR = "/usr/testbed";
150 151 152 153 154 155 156 157 158 159 160

#
# Support for Windows nodes.
# XXX here for compat; replaced by emulabconfig option.
#
my $WINSUPPORT = 1;

#
# Whether installation of all collab tools should be disabled.
# XXX here for compat; replaced by emulabconfig option.
#
Mike Hibler's avatar
Mike Hibler committed
161
my $NOCOLLAB   = 1;
162 163 164 165 166 167

#
# Enable elvin compatibility.
# XXX here for compat; replaced by emulabconfig option.
#
my $ELVIN_COMPAT = 0;
168

169 170 171
# This also gets turned on/off below
my $NOSETUP    = 0;

172 173 174
# Whether we configure a /scratch FS, turned on/off below
my $SCRATCHFS  = 0;

175 176 177
# Single or dual control network.
my $SINGLE_CONTROLNET = 0;

178 179 180
# Support a shared filesystem between fs server and nodes
my $SHAREDFS   = 1;

181 182 183
# When there is a shared FS via NFS, does it have the mountd race?
my $NFSRACY = 1;

184 185
# Start up the frisbee master server to act as an IGMP querier
# so that frisbee works (if there is no other querier running).
186
# -1 means let the system decide.
187
my $NEEDQUERIER = -1;
188

189 190 191
# Is ops a VM (Jail) on boss.
my $OPSVM = 0;

192 193 194
# Are we a XEN VM?
my $XENVM = 0;

195 196 197 198
#
# Node to use as ntp server for inner nodes and other inner servers.
# This node will use the outside "ntp1" server as its server.
#
199
# XXX this has never been tested with anything but "boss" and "ops".
200
#
201
my $NTPSERVER = "ops";
202

203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
#
# Defaults for configuration attributes (options).
# These can be overridden if values are passed in via the emulabconfig command.
#
my %emulabconfig = (
    #
    # Random stuff
    #
    "JAILIPBASE"  => "172.16.0.0",
    "JAILIPMASK"  => "255.240.0.0",
    "MFSTARBALL"  => "tftpboot-elabinelab.tar.gz",
    "MFSVERSION"  => "62",
    "MFSCONSOLE"  => "sio",

    #
    # Elabinelab configuration options:
    #
    #   CONFIG_NOSETUP	  debug option: don't do most of rc.mkelab activities.
    #   CONFIG_SCRATCHFS  configure a separate "scratch" filesystem.
    #   CONFIG_SINGLECNET use the real cnet as the inner cnet.
    #	CONFIG_ELVIN	support Elvin compatibility
    #	CONFIG_WINDOWS	support Windows OS on nodes
    #   CONFIG_COLLAB	install/configure for collaboration tools support.
    #	CONFIG_ARCHIVE	support integrated archival via svn (part of COLLAB)
    #   CONFIG_BUGSDB	support integrated bug database (part of COLLAB)
    #   CONFIG_CVS	support integrated CVS SCM (part of COLLAB)
    #   CONFIG_MAILMAN	support integrated mailman lists (part of COLLAB)
    #	CONFIG_USERDB	support integrated MySQL DB (part of COLLAB)
    #   CONFIG_WIKI	support integrated wiki (part of COLLAB)
232
    #	CONFIG_SHAREDFS	support shared filesystem	    
233
    #	CONFIG_QUERIER	configure mfrisbeed to act as IGMP querier
234 235 236 237 238 239 240 241 242 243 244 245 246
    #
    "CONFIG_NOSETUP"    => $NOSETUP,
    "CONFIG_SCRATCHFS"  => $SCRATCHFS,
    "CONFIG_SINGLECNET" => $SINGLE_CONTROLNET,
    "CONFIG_ELVIN"      => $ELVIN_COMPAT,
    "CONFIG_WINDOWS"    => $WINSUPPORT,
    "CONFIG_COLLAB"     => !$NOCOLLAB,
    "CONFIG_ARCHIVE"    => !$NOCOLLAB,
    "CONFIG_BUGSDB"     => !$NOCOLLAB,
    "CONFIG_CVS"        => !$NOCOLLAB,
    "CONFIG_MAILMAN"    => !$NOCOLLAB,
    "CONFIG_USERDB"     => !$NOCOLLAB,
    "CONFIG_WIKI"       => !$NOCOLLAB,
247
    "CONFIG_SHAREDFS"	=> $SHAREDFS,
248
    "CONFIG_NFSRACY"	=> $NFSRACY,
249
    "CONFIG_QUERIER"	=> $NEEDQUERIER,
250
    "CONFIG_OPSVM"	=> $OPSVM,
251
    "CONFIG_NODBINIT"   => 0,
252
    "CONFIG_GENIRACK"   => 0,
253 254 255

    # Default protogeni package if LOAD_PROTOGENI is enabled.
    "PGENI_PKG"		=> "emulab-protogeni-1.0",
256

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
    #
    # Elabinelab build options:
    #
    # 	LOAD_PACKAGES	download and install a standard set of packages,
    #	               	otherwise assume they are already installed.
    #   LOAD_PROTOGENI	load the optional Protogeni package.
    #                   This is different than the other "optional" packages
    #                   such as the collab tools which are installed via
    #                   {boss,ops}-install.  Pgeni still requires manual
    #                   intervention so boss-install doesn't even try.
    #   LOAD_MFS	download and install a tftpboot tarball,
    #	               	otherwise assume it is already installed.
    #   LOAD_ELABSOURCE	download, build and install the Emulab source code,
    #	               	otherwise assume it is already installed.
    #	LOAD_DB		download and install Emulab DB state,
    #			otherwise...this might not even be useful.
    #	LOAD_USERDIRS	download and install "user data" whatever we
    #			decide that might be.
    #
    # Defaults to all *but* LOAD_USERDIRS for backward compat.
    #
    "LOAD_PACKAGES"   => 1,
    "LOAD_PROTOGENI"  => 0,
    "LOAD_MFS"        => 1,
    "LOAD_ELABSOURCE" => 1,
    "LOAD_DB"         => 1,
    "LOAD_USERDIRS"   => 0,
);
285 286 287

# Version of FreeBSD.
my $FBSD_VERSION = 4;
288
if (`uname -r` =~ /^(\d+\.\d*)/) {
289 290 291 292 293 294
    $FBSD_VERSION = $1;
}
else {
    die("Could not determine what version of FreeBSD you are running!\n");
}

295 296 297 298 299 300 301 302 303
# Architecture
my $FBSD_ARCH = "i386";
if (`uname -m` =~ /^(\S+)$/) {
    $FBSD_ARCH = $1;
}
else {
    die("Could not determine what architecutre FreeBSD is running on!\n");
}

304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
#
# Find out our domain name, so that we can qualify the localhost entry
#
if ($hostname =~ /[^.]+\.(.+)/) {
    $domain = $1;
}

#
# Find the outer domain for sending email to creator.
#
my $outer_domain;
if ($bossname =~ /[^.]+\.(.+)/) {
    $outer_domain = $1;
}

# Execute the action.
SWITCH: for ($action) {
    /^boot$/i && do {
	doboot();
	last SWITCH;
    };
    /^shutdown$/i && do {
	doshutdown();
	last SWITCH;
    };
    /^reconfig$/i && do {
	doreconfig();
	last SWITCH;
    };
    /^reset$/i && do {
	docleanup();
	last SWITCH;
    };
    fatal("Invalid action: $action\n");
}
exit(0);

# More protos
sub SetupFatal($);
343
sub mysystem($;$);
344
sub SetupOpsNode($);
345
sub SetupBossNode($);
346 347
sub CreateDefsFile($);
sub SetupSendMail($$);
348
sub GetEmulabSource($);
349
sub MungeMfsRoot($);
Mike Hibler's avatar
Mike Hibler committed
350 351
sub SetupTBDir($);
sub RecreateDir($$);
352 353
sub CreateOpsJail($);
sub SetupOpsJail();
354
sub FindExtraFSConfig($);
355 356
sub AddPackage($$$);
sub DelPackage($@);
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383

#
# Boot Action.
#
sub doboot()
{
    my @tmccresults;

    if (tmcc(TMCCCMD_EMULABCONFIG, undef, \@tmccresults) < 0) {
	fatal("Could not get Inner Emulab Config info from server!");
    }
    # If no results then do nothing. No inner elab.
    return 0
	if (! @tmccresults);

    if (!$debug) {
	print "Redirecting output to $LOGFILE\n";

	open(STDERR, ">  $LOGFILE") or die("opening $LOGFILE for STDERR: $!");
	open(STDOUT, ">> $LOGFILE") or die("opening $LOGFILE for STDOUT: $!");

	#
	# Turn off line buffering on output
	#
	STDOUT->autoflush(1);
	STDERR->autoflush(1);
    }
384 385 386 387 388 389

    #
    # Stash us into the BINDIR for later.
    #
    mysystem("cp -fp $0 $BINDIR/rc")
	if ("$0" ne "$BINDIR/rc/rc.mkelab");
390
    
Mike Hibler's avatar
Mike Hibler committed
391
    #
392
    # FreeBSD version specific adjustments for defaults.
Mike Hibler's avatar
Mike Hibler committed
393
    #
394 395 396
    if ($FBSD_VERSION >= 8.2) {
	$emulabconfig{"MFSVERSION"} = "82";
    } elsif ($FBSD_VERSION >= 7.2) {
397 398 399 400
	$emulabconfig{"MFSVERSION"} = "72";
    } else {
	$emulabconfig{"MFSVERSION"} = "62";
    }
401

402 403 404 405
    if ($FBSD_VERSION >= 9.2) {
	$emulabconfig{"CONFIG_NFSRACY"} = 0;
    }

406 407 408 409 410
    # Determine if a XEN VM.
    if (system("sysctl -n kern.vm_guest >/dev/null 2>&1") == 0) {
	my $vm_guest = `sysctl -n kern.vm_guest`;
	if ($vm_guest =~ /^xen$/) {
	    $XENVM = 1;
411
	    print "Running inside a XEN VM\n";
412 413 414
	}
    }

415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
    #
    # Need outer control router IP in lots of places.
    #
    if (! -e "$BOOTDIR/routerip") {
	fatal("$BOOTDIR/routerip does not exist!");
    }
    $outer_routerip = `cat $BOOTDIR/routerip`;
    chomp($outer_routerip);

    # And the outer netmask
    if (! -e "$BOOTDIR/mynetmask") {
	fatal("$BOOTDIR/mynetmask does not exist!");
    }
    $outer_netmask = `cat $BOOTDIR/mynetmask`;
    chomp($outer_netmask);
Mike Hibler's avatar
Mike Hibler committed
430

431 432 433 434 435 436 437
    # And the outer interface
    if (! -e "$BOOTDIR/controlif") {
	SetupFatal("$BOOTDIR/controlif does not exist!");
    }
    $outer_controlif = `cat $BOOTDIR/controlif`;
    chomp($outer_controlif);

438 439 440 441 442 443 444
    #
    # Turn the tmcc results into a hash first. Then call the boss or ops
    # setup function.
    #
    foreach my $line (@tmccresults) {
	if ($line =~ /^(.*)="(.+)"$/ ||
	    $line =~ /^(.*)=(.+)$/) {
445 446
	    my $key = $1;
	    my $val = $2;
447 448 449 450 451 452 453 454 455 456 457 458

	    #
	    # XXX backward compat
	    #
	    if ($key eq "WINSUPPORT") {
		$key = "CONFIG_WINDOWS";
	    } elsif ($key eq "NOSETUP") {
		$key = "CONFIG_NOSETUP";
	    } elsif ($key eq "SINGLE_CONTROLNET") {
		$key = "CONFIG_SINGLECNET";
	    }

459 460 461 462 463 464 465 466 467 468 469 470 471 472
	    $emulabconfig{$key} = $val;

	    #
	    # Handle ordered setting/clearing of aggregate options.
	    # These may be later overridden by individual options.
	    # 
	    if ($key eq "CONFIG_COLLAB") {
		$emulabconfig{"CONFIG_ARCHIVE"} = $val;
		$emulabconfig{"CONFIG_BUGSDB"} = $val;
		$emulabconfig{"CONFIG_CVS"} = $val;
		$emulabconfig{"CONFIG_MAILMAN"} = $val;
		$emulabconfig{"CONFIG_USERDB"} = $val;
		$emulabconfig{"CONFIG_WIKI"} = $val;
	    }
473 474 475
	}
    }

Mike Hibler's avatar
Mike Hibler committed
476
    #
477
    # XXX temporary backward compat til this (router) gets implemented
Mike Hibler's avatar
Mike Hibler committed
478 479 480
    #
    $emulabconfig{"ROLE"} = "boss"
	if ($emulabconfig{"ROLE"} eq "boss+router");
481 482 483 484 485 486
    $emulabconfig{"ROLE"} = "boss+fs"
	if ($emulabconfig{"ROLE"} eq "boss+fs+router");

    # Override the role when inside an ops jail. 
    $emulabconfig{"ROLE"} = "opsjail"
	if ($opsjail);
Mike Hibler's avatar
Mike Hibler committed
487

488 489 490 491 492 493 494 495 496
    #
    # XXX backward compat for short-lived NEEDMROUTED option.
    # mfrisbeed now serves the role that mrouted did briefly.
    #
    if (defined($emulabconfig{"CONFIG_MROUTED"}) &&
	$emulabconfig{"CONFIG_QUERIER"} == -1) {
	$emulabconfig{"CONFIG_QUERIER"} = $emulabconfig{"CONFIG_MROUTED"};
    }

497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
    #
    # Look for a private variable cache.
    #
    if ($emulabconfig{"ROLE"} eq "boss" &&
	exists($emulabconfig{"PRIVATE_VARIABLES"}) &&
	$emulabconfig{"PRIVATE_VARIABLES"} ne "") {
	my $filename = $emulabconfig{"PRIVATE_VARIABLES"};
	
	if (! -e $filename) {
	    SetupFatal("$filename does not exist");
	}
	open(CN, $filename)
	    or SetupFatal("Could not open $filename: $!");
	while (<CN>) {
	    if ($_ =~ /^([-\w]*)\s*=\s*(.*)$/) {
		my $key = $1;
		my $val = $2;
		if ($val =~ /^'(.+)'$/ ||
		    $val =~ /^"(.+)"$/) {
		    $val = $1;
		}
		$emulabconfig{$key} = "$val";
	    }
	}
	close(CN);
    }
	
524 525 526 527
    # Override NTPSERVER when singlenet; okay to use inner ops.
    $NTPSERVER = "ops"
	if ($emulabconfig{"CONFIG_SINGLECNET"});

528
    #
529
    # XXX not-so-temporary: adjust package info.
530
    #
531 532 533
    # There are defaults in sitevars passed via emulabconfig,
    # but they are almost always wrong...  So we ALWAYS override them
    # here; packages are just too intimately tied to the OS version.
534
    #
535 536 537 538 539 540 541 542 543
    if ($FBSD_VERSION == 4.10) {
	$emulabconfig{FS_PKG_DIR}   = "/share/freebsd/4.10/packages";
	$emulabconfig{OPS_PKG_DIR}  = "/share/freebsd/4.10/packages";
	$emulabconfig{BOSS_PKG_DIR} = "/share/freebsd/4.10/packages";
	$emulabconfig{FS_PKG}       = "emulab-fs-1.4";
	$emulabconfig{OPS_PKG}      = "emulab-ops-1.4";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-1.4";
    }
    elsif ($FBSD_VERSION == 5.4) {    
544 545 546 547 548 549 550
	$emulabconfig{FS_PKG_DIR}   = "/share/freebsd/5.4/packages";
	$emulabconfig{OPS_PKG_DIR}  = "/share/freebsd/5.4/packages";
	$emulabconfig{BOSS_PKG_DIR} = "/share/freebsd/5.4/packages";
	$emulabconfig{FS_PKG}       = "emulab-fs-2.0";
	$emulabconfig{OPS_PKG}      = "emulab-ops-2.0";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-2.0";
    }
551
    elsif ($FBSD_VERSION == 6.0) {
552 553 554 555 556 557 558
	$emulabconfig{FS_PKG_DIR}   = "/share/freebsd/6.0/packages";
	$emulabconfig{OPS_PKG_DIR}  = "/share/freebsd/6.0/packages";
	$emulabconfig{BOSS_PKG_DIR} = "/share/freebsd/6.0/packages";
	$emulabconfig{FS_PKG}       = "emulab-fs-2.0";
	$emulabconfig{OPS_PKG}      = "emulab-ops-2.0";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-2.0";
    }
559
    elsif ($FBSD_VERSION == 6.1 ||
Mike Hibler's avatar
Mike Hibler committed
560
	   $FBSD_VERSION == 6.2) {
561 562 563
	$emulabconfig{FS_PKG_DIR} = "/share/freebsd/6.1/packages";
	$emulabconfig{FS_PKG_DIR} .= ".elvincompat"
	    if ($emulabconfig{"CONFIG_ELVIN"});
564 565
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};
566 567 568 569
	$emulabconfig{FS_PKG}       = "emulab-fs-2.0";
	$emulabconfig{OPS_PKG}      = "emulab-ops-2.0";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-2.0";
    }
Mike Hibler's avatar
Mike Hibler committed
570
    elsif ($FBSD_VERSION == 6.3) {
571 572 573
	$emulabconfig{FS_PKG_DIR} = "/share/freebsd/6.3/packages";
	$emulabconfig{FS_PKG_DIR} .= ".elvincompat"
	    if ($emulabconfig{"CONFIG_ELVIN"});
Mike Hibler's avatar
Mike Hibler committed
574 575 576 577 578 579
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{FS_PKG}       = "emulab-fs-2.1";
	$emulabconfig{OPS_PKG}      = "emulab-ops-2.1";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-2.1";
    }
Mike Hibler's avatar
Mike Hibler committed
580
    elsif ($FBSD_VERSION == 7.2) {
581 582 583
	$emulabconfig{FS_PKG_DIR} = "/share/freebsd/7.2/packages";
	$emulabconfig{FS_PKG_DIR} .= ".elvincompat"
	    if ($emulabconfig{"CONFIG_ELVIN"});
584 585 586 587 588 589
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{FS_PKG}       = "emulab-fs-3.0";
	$emulabconfig{OPS_PKG}      = "emulab-ops-3.0";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-3.0";
    }
Mike Hibler's avatar
Mike Hibler committed
590
    elsif ($FBSD_VERSION == 7.3) {
591 592
	my $suf = ($FBSD_ARCH eq "amd64") ? "-64" : "";
	$emulabconfig{FS_PKG_DIR} = "/share/freebsd/7.3/packages${suf}";
Mike Hibler's avatar
Mike Hibler committed
593 594 595 596 597 598
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{FS_PKG}       = "emulab-fs-3.1";
	$emulabconfig{OPS_PKG}      = "emulab-ops-3.1";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-3.1";
    }
599
    elsif ($FBSD_VERSION == 8.2) {
Leigh B Stoller's avatar
Leigh B Stoller committed
600 601 602 603 604 605
	$emulabconfig{FS_PKG_DIR} = "/share/freebsd/8.2/packages";
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{FS_PKG}       = "emulab-fs-4.0";
	$emulabconfig{OPS_PKG}      = "emulab-ops-4.0";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-4.0";
606
	$emulabconfig{PACKAGE_TARBALL} = "FreeBSD-8.2-packages.tar.gz";
607
	$emulabconfig{PGENI_PKG}    = "emulab-protogeni-2.0";
608
    }
609 610 611 612 613 614 615 616 617 618 619
    elsif ($FBSD_VERSION >= 8.3 && $FBSD_VERSION < 9.0) {
	my $suf = ($FBSD_ARCH eq "amd64") ? "-64" : "";
	$emulabconfig{FS_PKG_DIR} = "/share/freebsd/8.3/packages${suf}";
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{FS_PKG}       = "emulab-fs-5.0";
	$emulabconfig{OPS_PKG}      = "emulab-ops-5.0";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-5.0";
	$emulabconfig{PACKAGE_TARBALL} = "FreeBSD-8.3-packages${suf}.tar.gz";
	$emulabconfig{PGENI_PKG}    = "emulab-protogeni-3.0";
    }
620
    elsif ($FBSD_VERSION >= 9.0 && $FBSD_VERSION < 9.2) {
621 622 623 624 625 626 627
	$emulabconfig{FS_PKG_DIR} = "/share/freebsd/9.0/packages";
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{FS_PKG}       = "emulab-fs-5.0";
	$emulabconfig{OPS_PKG}      = "emulab-ops-5.0";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-5.0";
	$emulabconfig{PACKAGE_TARBALL} = "FreeBSD-9.0-packages.tar.gz";
628
	$emulabconfig{PGENI_PKG}    = "emulab-protogeni-3.0";
629
    } elsif ($FBSD_VERSION >= 9.2 && $FBSD_VERSION < 10.0) {
630 631 632 633 634 635 636 637 638
	my $suf = ($FBSD_ARCH eq "amd64") ? "-64" : "";
	$emulabconfig{FS_PKG_DIR} = "/share/freebsd/9.2/packages${suf}";
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{FS_PKG}       = "emulab-fs-5.1";
	$emulabconfig{OPS_PKG}      = "emulab-ops-5.1";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-5.1";
	$emulabconfig{PACKAGE_TARBALL} = "FreeBSD-9.2-packages${suf}.tar.gz";
	$emulabconfig{PGENI_PKG}    = "emulab-protogeni-3.1";
639 640 641 642 643 644 645 646 647 648
    } elsif ($FBSD_VERSION >= 10.0) {
	my $suf = ($FBSD_ARCH eq "amd64") ? "-64" : "";
	$emulabconfig{FS_PKG_DIR} = "/share/freebsd/10.0/packages${suf}";
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{FS_PKG}       = "emulab-fs-6.0";
	$emulabconfig{OPS_PKG}      = "emulab-ops-6.0";
	$emulabconfig{BOSS_PKG}     = "emulab-boss-6.0";
	$emulabconfig{PACKAGE_TARBALL} = "FreeBSD-10.0-packages${suf}.tar.gz";
	$emulabconfig{PGENI_PKG}    = "emulab-protogeni-4.0";
649
    }
650 651 652 653
    #
    # If there is a package tarball, prefer that and grab it now.
    # XXX note that we do not download into $TBDIR, it gets moved later.
    #
654 655 656 657 658 659 660 661
    if (exists($emulabconfig{"PACKAGE_TARBALL"})) {
	$emulabconfig{FS_PKG_DIR}   = "$TBDIR/packages";
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};

	mysystem("fetch -q -o /usr/packages.tar.gz ".
		 "'http://${bossname}/downloads/" .
		 $emulabconfig{PACKAGE_TARBALL} . "'");
Leigh B Stoller's avatar
Leigh B Stoller committed
662
    }
663 664 665 666 667 668 669 670 671 672
    #
    # Otherwise, make sure the NFS-mounted package directories exist.
    #
    else {
	if (! -e $emulabconfig{"BOSS_PKG_DIR"} ||
	    ! -e $emulabconfig{"OPS_PKG_DIR"} ||
	    ! -e $emulabconfig{"FS_PKG_DIR"}) {
	    SetupFatal("Could not locate boss/ops/fs packages");
	}
    }
673

674 675 676
    #
    # XXX Copy in new mkextrafs if necessary
    #
677
    if (-e "/var/run/mkextrafs.pl") {
678 679
	# only copy if newer
	if (! -e "$BINDIR/mkextrafs.pl" ||
680
	    (stat("/var/run/mkextrafs.pl"))[9] >
681
	    (stat("$BINDIR/mkextrafs.pl"))[9]) {
682
	    mysystem("cp /var/run/mkextrafs.pl $BINDIR/");
683 684 685
	}
    }

Leigh B Stoller's avatar
Leigh B Stoller committed
686
    #
687 688
    # We no longer use a static password. Generate a random password and
    # stash it in /usr/testbed/etc.
Leigh B Stoller's avatar
Leigh B Stoller committed
689
    #
690 691 692 693 694 695 696 697
    if (! exists($emulabconfig{"PASSWORD"}) ||
	$emulabconfig{"PASSWORD"} eq "") {
	my $rand= `/bin/dd if=/dev/urandom count=128 bs=1 2>/dev/null | /sbin/md5`;
	if ($?) {
	    SetupFatal("Could not generate a root password");
	}
	chomp($rand);
	$emulabconfig{"PASSWORD"} = substr($rand, 0, 10);
Leigh B Stoller's avatar
Leigh B Stoller committed
698 699
    }

700 701 702 703 704 705 706 707 708 709
    #
    # Convert to an encrypted hash.
    #
    my @salt_chars = ('a'..'z','A'..'Z','0'..'9');
    my $salt = $salt_chars[rand(@salt_chars)] .
	$salt_chars[rand(@salt_chars)];
    my $passhash = crypt($emulabconfig{"PASSWORD"}, "\$1\$${salt}");
    mysystem("echo '$passhash' | /usr/sbin/pw usermod toor -H 0");
    mysystem("echo '$passhash' | /usr/sbin/pw usermod root -H 0");

710
    if (!exists($emulabconfig{PACKAGE_TARBALL})) {
711
	#
712
	# XXX To avoid NFS errors while copying goo from outer FS.
713 714 715
	#
	system("sysctl vfs.nfs.eacces_retry_enable=1 >/dev/null 2>&1");    
	system("sysctl vfs.nfs.eacces_retry_count=20 >/dev/null 2>&1");
716

717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
	#
	# Figure out where /share is coming from (outer fs node).
	# We need this below. Inside the ops jail, /packages is
	# already mounted.
	#
	$fsname = `mount | grep /users | head -1`;
	if ($?) {
	    fatal("Could not get mount information!");
	}
	if ($fsname =~ /^([-\w\.]+):/) {
	    $fsname = $1;
	}
	else {
	    fatal("Could not determine the name of the outer FS node!");
	}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
732 733
    }

734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
    my @stdopts = ();
    foreach my $opt (keys %emulabconfig) {
	if ($opt =~ /^(CONFIG|LOAD)_/ && $emulabconfig{$opt} != 0) {
	    push @stdopts, $opt;
	}
    }
    print "Setting up \"", uc($emulabconfig{"ROLE"}), "\" node";
    if (@stdopts > 0) {
	print ", options:\n  ", join(", ", sort @stdopts);
    }
    print "\n";

    #
    # Finally, actually do the setup!
    #
749 750 751 752 753 754 755 756
    if ($emulabconfig{"ROLE"} eq "fs") {
	SetupFsNode();
    }
    elsif ($emulabconfig{"ROLE"} eq "ops") {
	SetupOpsNode(0);
    }
    elsif ($emulabconfig{"ROLE"} eq "ops+fs") {
	SetupOpsNode(1);
757 758
    }
    elsif ($emulabconfig{"ROLE"} eq "boss") {
759 760 761 762 763 764 765
	SetupBossNode(0);
    }
    elsif ($emulabconfig{"ROLE"} eq "boss+fs") {
	SetupBossNode(1);
    }
    elsif ($emulabconfig{"ROLE"} eq "opsjail") {
	SetupOpsJail();
766
    }
767 768 769
    elsif ($emulabconfig{"ROLE"} eq "node") {
	;
    }
770
    else {
771
	fatal("Do not recognize role '". $emulabconfig{"ROLE"}. "'!\n");
772
    }
773 774 775 776 777
    print "Done!\n";
    return 0;
}

#
778
# Setup an fs node.
779
#
780
sub SetupFsNode()
781
{
782
    my $shareslice;
783
    my $FSDIR = $FSMOUNTDIR;
784

785
    my $fromscratch =
786 787
	($emulabconfig{"LOAD_ELABSOURCE"} && $emulabconfig{"LOAD_MFS"});
    my $installpkgs = $emulabconfig{"LOAD_PACKAGES"};
788

789 790 791 792 793 794 795 796
    #
    # XXX (hopefully) tmp hack for dealing with other FS OSes
    #
    my ($os, $rel) = split " ", `uname -sr`;
    if ($os ne "FreeBSD") {
	SetupFatal("FS node must run FreeBSD\n");
    }

797
    #
798 799 800 801 802 803 804 805
    # Create filesystems for fs use.  We need:
    #  * /usr/testbed		 => disk0s2e
    # for a "from scratch" build and:
    #  * /q (proj,users,scratch) => disk0s4e
    #  * /share			 => disk0s4f
    # for ops+fs and fs-only nodes.
    #
    if ($fromscratch) {
Mike Hibler's avatar
Mike Hibler committed
806
	SetupTBDir($TBDIR);
807
    }
808
    RecreateDir("$FSDIR", 1);
809 810 811 812
    my $fsdev = FindExtraFSConfig($FSDIR);
    if ($fsdev) {
	mysystem("$BINDIR/mkextrafs.pl -s 0 -r $fsdev -f -2 $FSDIR");
	$shareslice = "/dev/$fsdev" . "s1f";
813
    }
814 815
    else {
	mysystem("$BINDIR/mkextrafs.pl -f -2 $FSDIR");
816

817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
	#
	# XXX mkextrafs does not create the second filesystem, it only creates
	# the BSD partition.  So we need to determine the name of the disk
	# device in use, and create a filesystem on that 'f' partition.
	#
	my $disk = `mount | grep '0s4e on $FSDIR'`;
	if ($disk =~ /(\/dev\/\S+)s4e on/) {
	    $shareslice = "$1" . "s4f";
	} else {
	    SetupFatal("Could not parse mount info to find extra partition");
	}
    }
    # don't mount it yet, just remember
    mysystem("newfs $shareslice");
	
832 833 834
    #
    # Download Emulab source if necessary
    #
835
    if ($emulabconfig{"LOAD_ELABSOURCE"}) {
836 837 838 839
	RecreateDir("$TBDIR/src", 1);
	GetEmulabSource("$TBDIR/src");
    }

840 841 842
    # This avoids nfs mounts interruptions
    if (exists($emulabconfig{PACKAGE_TARBALL})) {
	RecreateDir("$TBDIR/packages", 1);
843
	mysystem("tar zxf /usr/packages.tar.gz -C $TBDIR");
844 845
    }

846 847 848 849
    #
    # The mirror tree is copied to temp storage, and then copied into
    # place later.
    #
850
    if ($domirror && -e "/proj/$pid/mirror") {
851
	print "Copying over mirror tree from /proj/$pid/mirror\n";
852
	mysystem("rsync -a --delete /proj/$pid/mirror $TBDIR", 3);
853 854
    }

855 856 857 858 859
    #
    # Stash the IP of the outer emulab for tmcc (and script above).
    # We use an IP to avoid DNS issues (there will be a DNS running inside).
    # Ditto for the current router. Need that for later (rc.inelab).
    # 
860
    mysystem("echo '${outer_bossip}' > $ETCDIR/outer_bossnode");
861 862
    mysystem("cp -p $BOOTDIR/routerip $ETCDIR/outer_router");

863 864 865 866 867 868 869 870 871 872 873 874 875 876
    #
    # Need outer ip and netmask and iface for hardwired config below.
    #
    if (! -e "$BOOTDIR/myip") {
	SetupFatal("$BOOTDIR/myip does not exist!");
    }
    my $outer_ip = `cat $BOOTDIR/myip`;
    chomp($outer_ip);
    
    #
    # We also need the hardwired config for the inner control network.
    # Major kludge; should get it from tmcd data.
    #
    my @ifacelist;
877 878 879
    my $inner_controlif;
    my $inner_ip;
    my $inner_netmask;
880
    my $inner_speed;
881

882
    if (! $emulabconfig{"CONFIG_SINGLECNET"}) {
883 884 885 886 887 888
	if (getifconfig(\@ifacelist) != 0 || !@ifacelist) {
	    SetupFatal("Could not get ifconfig from libsetup!");
	}
	$inner_controlif = $ifacelist[0]->{IFACE};
	$inner_ip        = $ifacelist[0]->{IPADDR};
	$inner_netmask   = $ifacelist[0]->{IPMASK};
889 890 891 892 893 894 895 896 897 898
	$inner_speed     = $ifacelist[0]->{SPEED};
	if ($inner_speed =~ /^(100|1000)Mbps$/) {
	    $inner_speed = $1;
	} else {
	    print STDERR
		"*** Unrecognized inner control net speed '$inner_speed';".
		" defaulting to 100Mbps\n";
		
	    $inner_speed = "100";
	}
899 900
    }

901 902 903 904 905 906 907 908 909 910 911 912
    #
    # Kill off any Emulab daemons that might freak once we have removed
    # Emulab accounts.  We have seen this happen with the program agent--
    # it runs amok, filling up its logfile (that has been unlinked) and
    # eventually /var, possibly before we can finish setting up.
    #
    foreach my $daemon (@DAEMONS) {
	if (-e "/var/run/$daemon.pid") {
	    system("kill `cat /var/run/$daemon.pid`");
	}
    }

913 914 915 916 917 918 919 920 921 922 923 924 925 926
    #
    # And make a best effort to kill off system daemons as well.
    # Some of these we will restart below since boss-install needs them.
    #
    foreach my $daemon (@SYSDAEMONS) {
	if (-e "/etc/rc.d/$daemon") {
	    system("/etc/rc.d/$daemon stop");
	} elsif (-e "/var/run/$daemon.pid") {
	    system("kill `cat /var/run/$daemon.pid`");
	} else {
	    system("killall $daemon");
	}
    }

927 928 929 930 931 932
    my $sshdpid = "";
    if (-r "/var/run/sshd.pid") {
	$sshdpid = `cat /var/run/sshd.pid`;
	chomp($sshdpid);
    }

933 934
    #
    # Run the prepare script to clear out the current accounts and such.
935
    # From this point on will need to log in as root.
936 937
    #
    print "Clearing out existing accounts and such\n";
938
    mysystem("$BINDIR/prepare -N");
939

940 941 942 943 944 945 946 947 948 949
    #
    # XXX prepare is a destructive beast.  It will take out the ld hints
    # file so ld.so won't have a search path.  Repair that now if it is gone
    # since ops-install will want to start apps that need libraries from
    # /usr/local/lib.
    #
    if (! -r "/var/run/ld-elf.so.hints") {
	system("/etc/rc.d/ldconfig start");
    }

950 951 952 953 954 955 956 957
    #
    # This is a fixup, cause prepare removes the vmname, which is needed
    # during the reboot to tell outer boss we are alive (rc.inelab).
    #
    if ($XENVM) {
	mysystem("echo '$vid' > $BOOTDIR/vmname");
    }

958 959 960 961 962 963 964 965 966
    #
    # XXX did I mention what an a**hole prepare can be?
    # Put back the sshd pid file that it removed so that that
    # the install scripts can HUP sshd.
    #
    if ($sshdpid) {
	mysystem("echo '$sshdpid' > /var/run/sshd.pid");
    }

967 968 969 970 971
    #
    # Remove the outer testbed startup script.
    #
    mysystem("rm -f /usr/local/etc/rc.d/testbed.sh");

972 973 974
    #
    # And clear some other stuff.
    # 
975
    mysystem("rm -rf $TBDIR/bin $TBDIR/lib");
976 977
    unlink("/etc/rc.conf.d/dhclient")
	if (-e "/etc/rc.conf.d/dhclient");
978 979
    unlink("/etc/rc.d/netif-emulab")
	if (-e "/etc/rc.d/netif-emulab");
980

981
    #
982 983
    # Load up packages if necessary
    #
984
    if ($installpkgs) {
985 986 987 988 989
	# XXX fer now: if not set, derive from the OPS info
	if (!$emulabconfig{FS_PKG_DIR} || !$emulabconfig{FS_PKG}) {
	    $emulabconfig{FS_PKG_DIR} = $emulabconfig{OPS_PKG_DIR};
	    ($emulabconfig{FS_PKG} = $emulabconfig{OPS_PKG}) =~ s/ops/fs/;
	}
990

991 992 993 994 995 996 997
	#
	# Do this as a separate step because PKG_DIR might be an NFS path,
	# but we must do the NFS unmounts before running ops-install. 
	# 
	if (!$emulabconfig{FS_PKG_DIR} || !$emulabconfig{FS_PKG}) {
	    SetupFatal("Could not get package info from Emulab!");
	}
998

999 1000
	print "Installing the fs metaport.\n";
	RecreateDir("/usr/ports", 1);
1001
	AddPackage($emulabconfig{FS_PKG}, $emulabconfig{FS_PKG_DIR}, 0);
1002
    }
1003 1004

    #
1005
    # Clean up a few things on the image and create symlinks into $FSDIR for
1006
    # /proj, /users, /groups and /scratch. Also allows /share to be created/
1007
    #
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
    print "Command: 'umount -A -t nfs'\n";
    print "Started at:  " . libsetup::TBTimeStamp() . "\n";
    system("umount -A -t nfs");
    if ($?) {
	print STDERR "*** umount of NFS filesystems failed\n";
    }
    #
    # Uber-paranoid: even if the umount says it works, don't trust it.
    # Move the old mount points out of the way no matter what.
    # It is not super critical that these be unmounted at this time as
    # we will be rebooting shortly anyway; we just need them out of the way.
    #
1020 1021 1022 1023
    RecreateDir("/users", 0);
    RecreateDir("/proj", 0);
    RecreateDir("/groups", 0);
    RecreateDir("/share", 0);
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034

    mysystem("mkdir $FSDIR/users $FSDIR/proj $FSDIR/groups $FSDIR/share");
    mysystem("ln -s $FSDIR/users /users");
    mysystem("ln -s $FSDIR/proj /proj");
    mysystem("ln -s $FSDIR/groups /groups");

    #
    # Setup /share.  The partition and filesystem were created above.
    #
    mysystem("mount $shareslice $FSDIR/share");
    mysystem("echo \"$shareslice $FSDIR/share ufs rw 0 2\" >> /etc/fstab");
1035
    mysystem("ln -s $FSDIR/share /share");
1036

1037 1038 1039 1040
    #
    # And the optional /scratch which share the same FS as /proj, et.al.
    #
    if ($emulabconfig{"CONFIG_SCRATCHFS"}) {
1041
	RecreateDir("/scratch", 0);
1042 1043
	mysystem("mkdir $FSDIR/scratch");
	mysystem("ln -s $FSDIR/scratch /scratch");
1044 1045
    }

Mike Hibler's avatar
Mike Hibler committed
1046 1047
    #
    # Lets mount the package dir so that we can pass off some stuff to
1048
    # the install scripts.
Mike Hibler's avatar
Mike Hibler committed
1049
    #
1050 1051 1052 1053
    if (! exists($emulabconfig{PACKAGE_TARBALL})) {
	RecreateDir("/packages", 1);
	mysystem("mount ${fsname}:" . $emulabconfig{FS_PKG_DIR} . " /packages");
    }
Mike Hibler's avatar
Mike Hibler committed
1054

1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
    #
    # Need these for rc.conf.
    # 
    my $bossnode_ip = $emulabconfig{"BOSSIP"};
    my $fsnode_ip  = $emulabconfig{"FSIP"};

    #
    # Need control network.
    #
    my $control_network = inet_ntoa(inet_aton($fsnode_ip) &
				    inet_aton("255.255.255.0")) . "/24";

    #
    # Need to create an /etc/rc.conf that is more suitable for fs.
    # I took most of this from our real ops node. It will be modified
    # by the fs-install script below.
    #
    print "Creating a new /etc/rc.conf\n";
    open(RC, ">/etc/rc.conf") or
	SetupFatal("Could not open /etc/rc.conf for writing: $!");

    print RC "inetd_enable=\"YES\"\n";
    print RC "sendmail_enable=\"NO\"\n";
    print RC "sshd_enable=\"YES\"\n";

    print RC "ntpdate_enable=\"YES\"\n";
1081 1082 1083 1084 1085
    if ($NTPSERVER eq "fs") {
	print RC "ntpdate_flags=\"ntp1.${outer_domain}\"\n";
    } else {
	print RC "ntpdate_flags=\"$NTPSERVER\"\n";
    }
1086 1087 1088 1089 1090
    if ($FBSD_VERSION >= 5) {
	print RC "ntpd_enable=\"YES\"\n";
    } else {
	print RC "xntpd_enable=\"YES\"\n";
    }
1091

1092 1093
    print RC "rpcbind_enable=\"YES\"\n";
    print RC "mountd_enable=\"YES\"\n";
1094 1095 1096
    print RC "nfs_server_enable=\"YES\"\n";
    print RC "nfs_server_flags=\"-u -t -n 8\"\n";
    print RC "nfs_client_enable=\"YES\"\n";
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
    if ($emulabconfig{"CONFIG_WINDOWS"}) {
	#
	# As of 10/2012, the startup for samba changed.
	# XXX not directly related to the FreeBSD version, but it is
	# the best we can do--the port version was not bumped when this
	# change was made.
	#
	if ($FBSD_VERSION >= 8.3) {
	    print RC "samba_enable=\"YES\"\n";
	    print RC "nmbd_enable=\"NO\"\n";
	} else {
	    print RC "smbd_enable=\"YES\"\n";
	}
    }
1111 1112
    print RC "mountd_flags=\"-r -p 900\"\n";

1113
    print RC "network_interfaces=\"$outer_controlif\"\n";
1114 1115
    print RC "ifconfig_${outer_controlif}=".
	"\"inet $outer_ip netmask $outer_netmask\"\n";
1116

1117
    if (! $emulabconfig{"CONFIG_SINGLECNET"}) {
1118 1119 1120
	print RC "network_interfaces=\"\$network_interfaces $inner_controlif\"\n";
	print RC "ifconfig_${inner_controlif}=".
	    "\"inet $inner_ip netmask $inner_netmask ".
1121
	    "media ${inner_speed}baseTX mediaopt full-duplex\"\n";
1122 1123
    }
    print RC "network_interfaces=\"\$network_interfaces lo0\"\n";
1124 1125 1126 1127
    print RC "static_routes=\"outerboss vnodes\"\n";
    print RC "route_outerboss=\"$outer_bossip $outer_routerip\"\n";
    print RC "route_vnodes=\"-net ". $emulabconfig{"JAILIPBASE"} .
	" -netmask " . $emulabconfig{"JAILIPMASK"} .
1128
	" -iface " . ($emulabconfig{"CONFIG_SINGLECNET"} ?
1129
		      $outer_controlif : $inner_controlif) . "\"\n";
1130
    # Leave default route pointing to control network until setup complete.
1131 1132
    if ($emulabconfig{"CONFIG_NOSETUP"} ||
	$emulabconfig{"CONFIG_SINGLECNET"}) {
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
	print RC "defaultrouter=\"$outer_routerip\"\n";
    }
    else {
	print RC "defaultrouter=\"$bossnode_ip\"\n";
    }
    print RC "hostname=\"" . $emulabconfig{"FSNODE"} . "." . $domain . "\"\n";
    close(RC);

    #
    # Remove some cruft from /etc/syslog.conf
    #
    mysystem("cat /etc/syslog.conf | grep -v '\@users' > /tmp/syslog.conf");
    mysystem("cp -pf /etc/syslog.conf /etc/syslog.conf.old ; ".
	     "cp /tmp/syslog.conf /etc/syslog.conf");

    #
    # Create a defs file. Note that this will move to boss at some point.
    #
1151
    CreateDefsFile("$TBDIR/src/testbed/defs-elabinelab");
1152 1153

    goto skipsetup
1154
	if ($emulabconfig{"CONFIG_NOSETUP"});
1155 1156 1157 1158

    #
    # Configure an object tree. 
    #
1159
    RecreateDir("$TBDIR/obj/testbed", 1);
1160 1161 1162
    mysystem("cd $TBDIR/obj/testbed; ".
	     "   $TBDIR/src/testbed/configure ".
	     "      --with-TBDEFS=$TBDIR/src/testbed/defs-elabinelab ".
1163 1164
	     ($emulabconfig{"CONFIG_WINDOWS"} ?
	      "--enable-windows" : "--disable-windows"));
1165 1166 1167 1168

    #
    # Create the fs node.
    #
1169 1170 1171 1172 1173 1174 1175
    if (exists($emulabconfig{PACKAGE_TARBALL