rc.mkelab 54.2 KB
Newer Older
1 2 3
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2004-2008 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17
# All rights reserved.
#
# 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;

18 19 20
# XXX not yet complete
my $domirror = 0;

21 22 23 24 25 26 27 28 29
sub usage()
{
    print "Usage: " .
	scriptname() . " boot|shutdown|reconfig|reset\n";
    exit(1);
}
my $optlist = "ds";
my $action  = "boot";
my $debug   = 0;
30
my $skipit  = 1;	# Temporary until images updated.
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

# 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)
    if (REMOTE() || JAILED() || DELAYHOST());

# 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;
}
# Allow default above.
if (@ARGV) {
    $action = $ARGV[0];
}

# More stuff we need below.
my $TBDIR;
my $domain;
my ($pid,$eid,undef) = check_nickname();
my $file    = TMCREATOR();
my $creator = `cat $file`;
chomp($creator);

my $hostname = `hostname`;
chomp($hostname);
94
my ($bossname, $outer_bossip) = tmccbossinfo();
95

96 97 98 99 100
# 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;

Leigh B. Stoller's avatar
Leigh B. Stoller committed
101 102 103
# Outer FS node name. See below.
my $fsname;

104 105
# Cert stuff to give the inner emulab
my $RPCCERT = "/usr/testbed/etc/outer_emulab.pem";
106
#my $RPCPORT = 7778;
107

108 109 110
# This gets turned on/off below
my $WINSUPPORT = 0;

111 112 113
# This also gets turned on/off below
my $NOSETUP    = 0;

114 115 116
# Whether we configure a /scratch FS, turned on/off below
my $SCRATCHFS  = 0;

117 118 119
# Whether installation of collab tools should be disabled
my $NOCOLLAB   = 0;

120 121 122
# Single or dual control network.
my $SINGLE_CONTROLNET = 0;

123 124 125
# Enable elvin compatibility
my $ELVIN_COMPAT = 0;

126 127 128 129 130
# This will not change ...
my $PHP4_PKG = "php4-extensions-1.0";

# Version of FreeBSD.
my $FBSD_VERSION = 4;
131
if (`uname -r` =~ /^(\d\.\d*)/) {
132 133 134 135 136 137
    $FBSD_VERSION = $1;
}
else {
    die("Could not determine what version of FreeBSD you are running!\n");
}

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
#
# 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($);
177
sub mysystem($;$);
178
sub SetupOpsNode($);
179 180 181
sub SetupBossNode();
sub CreateDefsFile($);
sub SetupSendMail($$);
182
sub GetEmulabSource($);
183
sub MungeMfsRoot($);
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201

#
# 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);

    #
    # This is temporary until images are up to date.
    #
202
    if (0 && ! $skipit) {
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
	print "*** Installing current software first ... \n";
	
	mysystem("cd /users/stoller/testbed/obj-real/tmcd/common; ".
		 "gmake local-install");
	exec($PROGRAM_NAME, ("-s"));
	die("*** $0:\n".
	    "    Could not re-exec script!\n");
    }

    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);
    }
    
Mike Hibler's avatar
Mike Hibler committed
225 226 227 228 229 230 231
    #
    # XXX defaults for things that may or may not be passed in.
    # Will be overridden if values are actually passed in.
    #
    $emulabconfig{"JAILIPBASE"} = "172.16.0.0";
    $emulabconfig{"JAILIPMASK"} = "255.240.0.0";
    $emulabconfig{"MFSTARBALL"} = "tftpboot-elabinelab.tar.gz";
Mike Hibler's avatar
Mike Hibler committed
232
    $emulabconfig{"MFSVERSION"} = "62";
Mike Hibler's avatar
Mike Hibler committed
233 234
    $emulabconfig{"MFSCONSOLE"} = "sio";
    $emulabconfig{"WINSUPPORT"} = 0;
235
    $emulabconfig{"NOSETUP"}    = 0;
236
    $emulabconfig{"SCRATCHFS"}  = 0;
237
    $emulabconfig{"SINGLE_CONTROLNET"} = 0;
238 239 240 241 242
    if (-x "/usr/local/libexec/elvind") {
	$emulabconfig{"ELVIN_COMPAT"} = 1;
    } else {
	$emulabconfig{"ELVIN_COMPAT"} = 0;
    }
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258

    #
    # 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
259

260 261 262 263 264 265 266 267 268 269 270
    #
    # Turn the tmcc results into a hash first. Then call the boss or ops
    # setup function.
    #
    foreach my $line (@tmccresults) {
	if ($line =~ /^(.*)="(.+)"$/ ||
	    $line =~ /^(.*)=(.+)$/) {
	    $emulabconfig{$1} = $2;
	}
    }

Mike Hibler's avatar
Mike Hibler committed
271
    #
272
    # XXX temporary backward compat til this get implemented
Mike Hibler's avatar
Mike Hibler committed
273 274 275 276
    #
    $emulabconfig{"ROLE"} = "boss"
	if ($emulabconfig{"ROLE"} eq "boss+router");

277 278 279 280
    #
    # XXX To avoid NFS errors while copying goo from outer boss.
    # 
    system("sysctl vfs.nfs.eacces_retry_enable=1 >/dev/null 2>&1");    
281 282
    system("sysctl vfs.nfs.eacces_retry_count=20 >/dev/null 2>&1");

283
    # Turn on windows support.
Mike Hibler's avatar
Mike Hibler committed
284
    if ($emulabconfig{"WINSUPPORT"}) {
285 286
	$WINSUPPORT = 1;
    }
287 288 289 290
    # Ditto nosetup.
    if ($emulabconfig{"NOSETUP"}) {
	$NOSETUP = 1;
    }
291 292 293 294
    # and scratch filesystem usage
    if ($emulabconfig{"SCRATCHFS"}) {
	$SCRATCHFS = 1;
    }
295 296
    # and single vs dual control network
    if ($emulabconfig{"SINGLE_CONTROLNET"}) {
297
	$SINGLE_CONTROLNET = 1;
298
    }
299 300 301 302
    # and elvin compatibility
    if ($emulabconfig{"ELVIN_COMPAT"}) {
	$ELVIN_COMPAT = 1;
    }
303

304
    # XXX Temporary
305
    if ($FBSD_VERSION == 5.4) {    
306 307 308 309 310 311 312
	$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";
    }
313
    elsif ($FBSD_VERSION == 6.0) {
314 315 316 317 318 319 320
	$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";
    }
321
    elsif ($FBSD_VERSION == 6.1 ||
Mike Hibler's avatar
Mike Hibler committed
322
	   $FBSD_VERSION == 6.2) {
323 324 325 326 327 328 329
	if ($ELVIN_COMPAT) {
	    $emulabconfig{FS_PKG_DIR} = "/share/freebsd/6.1/packages.elvincompat";
	} else {
	    $emulabconfig{FS_PKG_DIR} = "/share/freebsd/6.1/packages";
	}
	$emulabconfig{OPS_PKG_DIR}  = $emulabconfig{FS_PKG_DIR};
	$emulabconfig{BOSS_PKG_DIR} = $emulabconfig{FS_PKG_DIR};
330 331 332 333
	$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
334 335 336 337 338 339 340 341 342 343 344 345
    elsif ($FBSD_VERSION == 6.3) {
	if ($ELVIN_COMPAT) {
	    $emulabconfig{FS_PKG_DIR} = "/share/freebsd/6.3/packages.elvincompat";
	} else {
	    $emulabconfig{FS_PKG_DIR} = "/share/freebsd/6.3/packages";
	}
	$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";
    }
346

Leigh B. Stoller's avatar
Leigh B. Stoller committed
347 348 349 350 351 352 353 354 355 356 357 358 359
    # Figure out where /share is coming from (outer fs node). We need
    # that below.
    $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!");
    }

360 361 362 363 364 365 366 367
    if ($emulabconfig{"ROLE"} eq "fs") {
	SetupFsNode();
    }
    elsif ($emulabconfig{"ROLE"} eq "ops") {
	SetupOpsNode(0);
    }
    elsif ($emulabconfig{"ROLE"} eq "ops+fs") {
	SetupOpsNode(1);
368 369 370 371 372 373 374 375 376
    }
    elsif ($emulabconfig{"ROLE"} eq "boss") {
	SetupBossNode();
    }
    print "Done!\n";
    return 0;
}

#
377
# Setup an fs node.
378
#
379
sub SetupFsNode()
380
{
381 382
    print "Setting up an Fs node ...\n";
    $TBFS = "/q";
383 384
    $TBDIR = "/q";

385 386 387 388 389 390 391 392
    #
    # 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");
    }

393 394 395
    #
    # Create a ${TBDIR} from the extra slice and put everything there.
    # 
396 397 398
    mysystem("mkdir ${TBFS}")
	if (! -d "${TBFS}");
    mysystem("$BINDIR/mkextrafs.pl -f ${TBFS}");
399 400 401 402
    mysystem("mkdir ${TBDIR}/testbed");
    mysystem("mkdir ${TBDIR}/testbed/src");
    mysystem("mkdir ${TBDIR}/testbed/obj");

403
    GetEmulabSource("${TBDIR}/testbed/src");
404

405 406 407 408
    #
    # The mirror tree is copied to temp storage, and then copied into
    # place later.
    #
409
    if ($domirror && -e "/proj/$pid/mirror") {
410
	print "Copying over mirror tree from /proj/$pid/mirror\n";
411
	mysystem("rsync -a --delete /proj/$pid/mirror ${TBDIR}", 3);
412 413
    }

414 415 416 417 418
    #
    # 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).
    # 
419
    mysystem("echo '${outer_bossip}' > $ETCDIR/outer_bossnode");
420 421
    mysystem("cp -p $BOOTDIR/routerip $ETCDIR/outer_router");

422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
    #
    # 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);
    
    if (! -e "$BOOTDIR/controlif") {
	SetupFatal("$BOOTDIR/controlif does not exist!");
    }
    my $outer_controlif = `cat $BOOTDIR/controlif`;
    chomp($outer_controlif);

    #
    # We also need the hardwired config for the inner control network.
    # Major kludge; should get it from tmcd data.
    #
    my @ifacelist;
442 443 444 445 446 447 448 449 450 451 452
    my $inner_controlif;
    my $inner_ip;
    my $inner_netmask;

    if (! $SINGLE_CONTROLNET) {
	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};
453 454
    }

455 456 457 458 459
    #
    # Run the prepare script to clear out the current accounts and such.
    # From this point on will need to log in as root,
    #
    print "Clearing out existing accounts and such\n";
460
    mysystem("$BINDIR/prepare -N");
461 462 463 464 465 466

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

467 468 469
    #
    # And clear some other stuff.
    # 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
470 471
    mysystem("rm -rf /usr/testbed/lib");
    mysystem("rm -rf /usr/testbed/bin");
472 473
    unlink("/etc/rc.conf.d/dhclient")
	if (-e "/etc/rc.conf.d/dhclient");
474 475
    unlink("/etc/rc.d/netif-emulab")
	if (-e "/etc/rc.d/netif-emulab");
476

Mike Hibler's avatar
Mike Hibler committed
477 478 479
    goto skippkg
	if ($NOSETUP);

480 481 482 483 484 485
    # 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/;
    }

486
    #
487 488
    # 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. 
489
    # 
490
    if (!$emulabconfig{FS_PKG_DIR} || !$emulabconfig{FS_PKG}) {
491 492
	SetupFatal("Could not get package info from Emulab!");
    }
493 494
    print "Installing the fs metaport.\n";

495 496
    # Make sure /usr/ports is not a symlink to RO shared space
    if (-l "/usr/ports") {
Mike Hibler's avatar
Mike Hibler committed
497
	if (!unlink("/usr/ports")) {
498 499 500 501 502 503
	    print "WARNING: /usr/ports is a symlink, port install may fail\n";
	} else {
	    mysystem("mkdir /usr/ports");
	}
    }

504 505
    $ENV{"PKG_PATH"} = $emulabconfig{FS_PKG_DIR};
    mysystem("pkg_add $emulabconfig{FS_PKG} >/tmp/perrs 2>&1");
Mike Hibler's avatar
Mike Hibler committed
506
  skippkg:
507 508 509

    #
    # Clean up a few things on the image and create symlinks into ${TBDIR} for
510
    # /proj, /users, /groups and /scratch. Also allows /share to be created/
511 512 513 514 515
    #
    mysystem("umount -A -t nfs");
    # In case umount fails!
    mysystem("cd /; mv -f users users.old");
    mysystem("cd /; mv -f proj proj.old");
516 517
    mysystem("cd /; mv -f share share.old");
    # This might not exist
518 519 520 521 522 523 524
    mysystem("cd /; mv -f groups groups.old")
	if (-d "/groups");
    mysystem("mkdir ${TBDIR}/users ${TBDIR}/proj ${TBDIR}/groups");
    mysystem("ln -s ${TBDIR}/users /users");
    mysystem("ln -s ${TBDIR}/proj /proj");
    mysystem("ln -s ${TBDIR}/groups /groups");

525 526 527 528 529 530 531
    if ($SCRATCHFS) {
	mysystem("cd /; mv -f scratch scratch.old")
	    if (-d "/scratch");
	mysystem("mkdir ${TBDIR}/scratch");
	mysystem("ln -s ${TBDIR}/scratch /scratch");
    }

532 533 534
    #
    # Setup a stub /share using slice 2 of the image.
    #
535
    mysystem("mkdir /share");
536 537
    mysystem("$BINDIR/mkextrafs.pl -f -s 2 /share");

Mike Hibler's avatar
Mike Hibler committed
538 539 540 541 542 543 544 545 546
    #
    # Lets mount the package dir so that we can pass off some stuff to
    # the install scripts;
    #
    if (! -d "/packages") {
	mysystem("mkdir /packages");
    }
    mysystem("mount ${fsname}:" . $emulabconfig{FS_PKG_DIR} . " /packages");

547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
    #
    # 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";
    print RC "ntpdate_flags=\"boss\"\n";
    print RC "xntpd_enable=\"YES\"\n";
    print RC "linux_enable=\"YES\"\n";

577 578
    print RC "rpcbind_enable=\"YES\"\n";
    print RC "mountd_enable=\"YES\"\n";
579 580 581
    print RC "nfs_server_enable=\"YES\"\n";
    print RC "nfs_server_flags=\"-u -t -n 8\"\n";
    print RC "nfs_client_enable=\"YES\"\n";
Mike Hibler's avatar
Mike Hibler committed
582 583
    print RC "smbd_enable=\"YES\"\n"
	if ($WINSUPPORT);
584 585
    print RC "mountd_flags=\"-r -p 900\"\n";

586
    print RC "network_interfaces=\"$outer_controlif\"\n";
587 588
    print RC "ifconfig_${outer_controlif}=".
	"\"inet $outer_ip netmask $outer_netmask\"\n";
589 590 591 592 593 594 595 596

    if (! $SINGLE_CONTROLNET) {
	print RC "network_interfaces=\"\$network_interfaces $inner_controlif\"\n";
	print RC "ifconfig_${inner_controlif}=".
	    "\"inet $inner_ip netmask $inner_netmask ".
	    "media 100baseTX mediaopt full-duplex\"\n";
    }
    print RC "network_interfaces=\"\$network_interfaces lo0\"\n";
597 598 599 600
    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"} .
601 602
	" -iface " . ($SINGLE_CONTROLNET ?
		      $outer_controlif : $inner_controlif) . "\"\n";
603
    # Leave default route pointing to control network until setup complete.
604
    if ($NOSETUP || $SINGLE_CONTROLNET) {
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
	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.
    #
    CreateDefsFile("${TBDIR}/testbed/src/testbed/defs-elabinelab");

    goto skipsetup
	if ($NOSETUP);

    #
    # Configure an object tree. 
    #
    mysystem("mkdir -p ${TBDIR}/testbed/obj/testbed");
    mysystem("cd ${TBDIR}/testbed/obj/testbed; ".
	     "   ../../src/testbed/configure ".
	     "      --with-TBDEFS=../../src/testbed/defs-elabinelab ".
	     ($WINSUPPORT ? "--enable-windows" : "--disable-windows"));

Mike Hibler's avatar
Mike Hibler committed
637 638 639 640 641 642 643 644 645 646
    #
    # 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 fs-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");
    }

647 648 649
    #
    # Create the fs node.
    #
Mike Hibler's avatar
Mike Hibler committed
650
    $ENV{"PKG_PATH"} = "/packages";
Mike Hibler's avatar
Mike Hibler committed
651
    my $pkg = "-P $emulabconfig{FS_PKG} -p /packages";
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
    mysystem("cd ${TBDIR}/testbed/obj/testbed/install; ".
	     "   perl fs-install $pkg -b");

    #
    # And install the fs side.
    #
    mysystem("cd ${TBDIR}/testbed/obj/testbed; gmake fs-install");

    #
    # Ack! The prepare script above killed the pid file for mountd. This
    # is going to matter later when boss sets up and tries to add accounts.
    # We could reboot fs, but for now its easier if I let both nodes setup
    # before rebooting either one. So, restart mountd so it will create a
    # new pid file in /var/run. Another idea might be that we do not run
    # prepare, or scale it back for inner elab. Needs more thought.
    #
    mysystem("killall mountd");
Mike Hibler's avatar
Mike Hibler committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
    #
    # Its worse on FreeBSD5! We lost the rpcbind socket too. Killing
    # that means we have to restart nfsd so it can register.
    #
    if ($FBSD_VERSION >= 5) {
	#
	# The nfsd script will try to kill all nfsd processes, but once
	# the master is killed, it kills all children itself.  Thus the
	# nfsd script may fail to kill the children if they are already
	# dead and return non-zero.  So we ignore the return value of
	# the script by using system rather than mysystem.
	#
	system("/etc/rc.d/nfsd stop");
	mysystem("killall rpcbind");
	mysystem("rpcbind");
	mysystem("/etc/rc.d/nfsd start");
    }
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
    mysystem("mountd -r");

    #
    # Need to create a resolv.conf that points to inner boss. This is the
    # last thing we do cause after this, stuff is probably going to stop
    # working properly!
    # 
    print "Creating a new /etc/resolv.conf\n";
    open(RC, ">/etc/resolv.conf") or
	SetupFatal("Could not open /etc/resolv.conf for writing: $!");

    print RC "domain $domain\n";
    print RC "search $domain\n";
    print RC "nameserver $bossnode_ip\n";
    close(RC);

  skipsetup:
    #
    # Hmm, need to run this at startup though.
    # 
    mysystem("echo '/usr/local/etc/emulab/rc/rc.inelab' ".
	     "   >> /etc/rc.local");

    return
	if ($NOSETUP);

    #
    # Remove source code from fs so that mere users do not get access to it.
    # Something to do with licensing ...
    #
    mysystem("cp -p ${TBDIR}/testbed/src/testbed/defs-elabinelab ".
	     "      ${TBDIR}/testbed/src");
    mysystem("rm -rf ${TBDIR}/testbed/src/testbed");
    mysystem("rm -rf ${TBDIR}/testbed/obj/testbed");

    #
    # Copy the mirror tree into place. Do not use rsync.
    #
Mike Hibler's avatar
Mike Hibler committed
724
    if (0 && -e "${TBDIR}/mirror") {
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
	print "Copying mirror tree into place\n";
	mysystem("cp -Rfp ${TBDIR}/mirror/ /");
    }
}

#
# Setup an ops node.
#
sub SetupOpsNode($)
{
    my ($isfs) = @_;

    print "Setting up an " . ($isfs ? "Ops/Fs" : "Ops") . " node ...\n";

    if ($isfs) {
	$TBFS = "/q";
	$TBDIR = "/q";
    } else {
	$TBFS = "/usr/testbed";
	$TBDIR = "/usr";
    }

    #
    # Create a ${TBFS} from the extra slice and put everything there.
    # 
    mysystem("mkdir ${TBFS}")
	if (! -d "${TBFS}");
    mysystem("$BINDIR/mkextrafs.pl -f ${TBFS}");
    mysystem("mkdir ${TBDIR}/testbed")
	if (! -d "${TBDIR}/testbed");
    mysystem("mkdir ${TBDIR}/testbed/src");
    mysystem("mkdir ${TBDIR}/testbed/obj");

    GetEmulabSource("${TBDIR}/testbed/src");

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

    #
    # 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).
    # 
    mysystem("echo '${outer_bossip}' > $ETCDIR/outer_bossnode");
    mysystem("cp -p $BOOTDIR/routerip $ETCDIR/outer_router");

    #
    # 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);
    
    if (! -e "$BOOTDIR/controlif") {
	SetupFatal("$BOOTDIR/controlif does not exist!");
    }
    my $outer_controlif = `cat $BOOTDIR/controlif`;
    chomp($outer_controlif);

    #
    # We also need the hardwired config for the inner control network.
    # Major kludge; should get it from tmcd data.
    #
    my @ifacelist;
797 798 799 800 801 802 803 804 805 806 807
    my $inner_controlif;
    my $inner_ip;
    my $inner_netmask;

    if (! $SINGLE_CONTROLNET) {
	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};
808 809 810 811 812 813 814
    }

    #
    # Run the prepare script to clear out the current accounts and such.
    # From this point on will need to log in as root,
    #
    print "Clearing out existing accounts and such\n";
815
    mysystem("$BINDIR/prepare -N");
816 817 818 819 820 821 822 823 824 825 826

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

    #
    # And clear some other stuff.
    # 
    mysystem("rm -rf /usr/testbed/lib");
    mysystem("rm -rf /usr/testbed/bin");
827 828
    unlink("/etc/rc.conf.d/dhclient")
	if (-e "/etc/rc.conf.d/dhclient");
829 830
    unlink("/etc/rc.d/netif-emulab")
	if (-e "/etc/rc.d/netif-emulab");
831

832 833 834
    goto skippkg
	if ($NOSETUP);
    
835 836 837 838 839 840 841
    #
    # 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{OPS_PKG_DIR} || !$emulabconfig{OPS_PKG}) {
	SetupFatal("Could not get package info from Emulab!");
    }
842
    print "Removing conflicting packages.\n";
843 844
    mysystem("pkg_delete -r -x mysql-client")
	if (-e "/usr/local/bin/mysql");
845
    
846
    print "Installing the ops metaport.\n";
847 848 849

    # Make sure /usr/ports is not a symlink to RO shared space
    if (-l "/usr/ports") {
Mike Hibler's avatar
Mike Hibler committed
850
	if (!unlink("/usr/ports")) {
851 852 853 854 855 856
	    print "WARNING: /usr/ports is a symlink, port install may fail\n";
	} else {
	    mysystem("mkdir /usr/ports");
	}
    }

857 858
    $ENV{"PKG_PATH"} = $emulabconfig{OPS_PKG_DIR};
    mysystem("pkg_add $emulabconfig{OPS_PKG} >/tmp/perrs 2>&1");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
859

860 861 862 863 864 865 866
    if ($isfs) {
	# XXX 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/;
	}
    }
867
  skippkg:
868 869 870

    #
    # Clean up a few things on the image and create symlinks into ${TBDIR} for
871
    # /proj, /users, /groups and /scratch. Also allows /share to be created/
872 873 874 875 876 877
    #
    mysystem("umount -A -t nfs");
    # In case umount fails!
    mysystem("cd /; mv -f users users.old");
    mysystem("cd /; mv -f proj proj.old");
    mysystem("cd /; mv -f share share.old");
878
    # This might not exist
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895
    mysystem("cd /; mv -f groups groups.old")
	if (-d "/groups");
    if ($isfs) {
	mysystem("mkdir ${TBDIR}/users ${TBDIR}/proj ${TBDIR}/groups");
	mysystem("ln -s ${TBDIR}/users /users");
	mysystem("ln -s ${TBDIR}/proj /proj");
	mysystem("ln -s ${TBDIR}/groups /groups");

	#
	# Setup a stub /share using slice 2 of the image.
	#
	mysystem("mkdir /share");
	mysystem("$BINDIR/mkextrafs.pl -f -s 2 /share");
    } else {
	mysystem("mkdir /users /proj /groups /share");
    }

896 897 898 899 900 901 902 903 904 905 906
    if ($SCRATCHFS) {
	mysystem("cd /; mv -f scratch scratch.old")
	    if (-d "/scratch");
	if ($isfs) {
	    mysystem("mkdir ${TBDIR}/scratch");
	    mysystem("ln -s ${TBDIR}/scratch /scratch");
	} else {
	    mysystem("mkdir /scratch");
	}
    }

Leigh B. Stoller's avatar
Leigh B. Stoller committed
907 908 909 910 911 912 913 914 915
    #
    # Lets mount the package dir so that we can pass off some stuff to
    # the install scripts;
    #
    if (! -d "/packages") {
	mysystem("mkdir /packages");
    }
    mysystem("mount ${fsname}:" . $emulabconfig{OPS_PKG_DIR} . " /packages");

916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946
    #
    # Need these for rc.conf.
    # 
    my $bossnode_ip = $emulabconfig{"BOSSIP"};
    my $opsnode_ip  = $emulabconfig{"OPSIP"};

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

    #
    # Need to create an /etc/rc.conf that is more suitable for ops.
    # I took most of this from our real ops node. It will be modified
    # by the ops-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=\"YES\"\n";
    print RC "sshd_enable=\"YES\"\n";

    print RC "ntpdate_enable=\"YES\"\n";
    print RC "ntpdate_flags=\"boss\"\n";
    print RC "xntpd_enable=\"YES\"\n";
    print RC "linux_enable=\"YES\"\n";
    print RC "accounting_enable=\"YES\"\n";

947 948
    print RC "rpcbind_enable=\"YES\"\n";
    print RC "mountd_enable=\"YES\"\n";
949 950 951
    print RC "nfs_server_enable=\"YES\"\n";
    print RC "nfs_server_flags=\"-u -t -n 8\"\n";
    print RC "nfs_client_enable=\"YES\"\n";
952 953
    print RC "smbd_enable=\"YES\"\n"
	if ($WINSUPPORT);
954 955 956 957
    print RC "mountd_flags=\"-r -p 900\"\n";

    print RC "syslogd_flags=\"-a $control_network\"\n";

958
    print RC "network_interfaces=\"$outer_controlif\"\n";
959
    print RC "ifconfig_${outer_controlif}=".
960
	"\"inet $outer_ip netmask $outer_netmask\"\n";
961 962 963 964 965 966 967 968
    
    if (! $SINGLE_CONTROLNET) {
	print RC "network_interfaces=\"\$network_interfaces $inner_controlif\"\n";
	print RC "ifconfig_${inner_controlif}=".
	    "\"inet $inner_ip netmask $inner_netmask ".
	    "media 100baseTX mediaopt full-duplex\"\n";
    }
    print RC "network_interfaces=\"\$network_interfaces lo0\"\n";
Mike Hibler's avatar
Mike Hibler committed
969
    print RC "static_routes=\"outerboss vnodes\"\n";
970
    print RC "route_outerboss=\"$outer_bossip $outer_routerip\"\n";
Mike Hibler's avatar
Mike Hibler committed
971 972
    print RC "route_vnodes=\"-net ". $emulabconfig{"JAILIPBASE"} .
	" -netmask " . $emulabconfig{"JAILIPMASK"} .
973 974
	" -iface " . ($SINGLE_CONTROLNET ?
		      $outer_controlif : $inner_controlif) . "\"\n";
975
    # Leave default route pointing to control network until setup complete.
976
    if ($NOSETUP || $SINGLE_CONTROLNET) {
977 978 979 980 981
	print RC "defaultrouter=\"$outer_routerip\"\n";
    }
    else {
	print RC "defaultrouter=\"$bossnode_ip\"\n";
    }
982 983 984
    print RC "hostname=\"" . $emulabconfig{"OPSNODE"} . "." . $domain . "\"\n";
    close(RC);

985 986 987 988 989 990 991
    #
    # 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");

992 993 994 995 996
    #
    # Create a defs file. Note that this will move to boss at some point.
    #
    CreateDefsFile("${TBDIR}/testbed/src/testbed/defs-elabinelab");

997 998 999
    goto skipsetup
	if ($NOSETUP);

1000 1001 1002 1003 1004 1005
    #
    # Configure an object tree. 
    #
    mysystem("mkdir -p ${TBDIR}/testbed/obj/testbed");
    mysystem("cd ${TBDIR}/testbed/obj/testbed; ".
	     "   ../../src/testbed/configure ".
1006
	     "      --with-TBDEFS=../../src/testbed/defs-elabinelab ".
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1007
	     ($WINSUPPORT ? "--enable-windows" : "--disable-windows"));
1008 1009 1010 1011

    #
    # Create the ops node.
    #
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1012 1013
    $ENV{"PKG_PATH"} = "/packages";
    my $pkg = "-P $emulabconfig{OPS_PKG} -p /packages " .
1014
	($isfs ? "-F $emulabconfig{FS_PKG}" : "");
1015
    mysystem("cd ${TBDIR}/testbed/obj/testbed/install; ".
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1016
	     "   perl ops-install $pkg -b -w ElabInElab ");
1017 1018 1019 1020

    #
    # And install the ops side.
    #
1021 1022
    my $itarget = $isfs ? "opsfs-install" : "ops-install";
    mysystem("cd ${TBDIR}/testbed/obj/testbed; gmake $itarget");
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045

    #
    # Lets populate the mail lists with the creator of the experiment so
    # that email goes someplace useful.
    # 
    opendir(DIR, "/etc/mail/lists") or
	SetupFatal("Cannot opendir /etc/mail/lists: $!");
    my @lists = grep { $_ ne "." && $_ ne ".." } readdir(DIR);
    closedir(DIR);

    foreach my $list (@lists) {
	mysystem("echo ${creator}\@${outer_domain} > /etc/mail/lists/$list");
    }

    #
    # Ack! The prepare script above killed the pid file for mountd. This
    # is going to matter later when boss sets up and tries to add accounts.
    # We could reboot ops, but for now its easier if I let both nodes setup
    # before rebooting either one. So, restart mountd so it will create a
    # new pid file in /var/run. Another idea might be that we do not run
    # prepare, or scale it back for inner elab. Needs more thought.
    #
    mysystem("killall mountd");
1046 1047 1048 1049 1050
    #
    # Its worse on FreeBSD5! We lost the rpcbind socket too. Killing
    # that means we have to restart nfsd so it can register.
    #
    if ($FBSD_VERSION >= 5) {
1051 1052 1053 1054
	#
	# The nfsd script will try to kill all nfsd processes, but once
	# the master is killed, it kills all children itself.  Thus the
	# nfsd script may fail to kill the children if they are already
1055 1056
	# dead and return non-zero.  So we ignore the return value of
	# the script by using system rather than mysystem.
1057
	#
1058
	system("/etc/rc.d/nfsd stop");
1059 1060 1061 1062
	mysystem("killall rpcbind");
	mysystem("rpcbind");
	mysystem("/etc/rc.d/nfsd start");
    }
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
    mysystem("mountd -r");

    #
    # Need to create a resolv.conf that points to inner boss. This is the
    # last thing we do cause after this, stuff is probably going to stop
    # working properly!
    # 
    print "Creating a new /etc/resolv.conf\n";
    open(RC, ">/etc/resolv.conf") or
	SetupFatal("Could not open /etc/resolv.conf for writing: $!");

    print RC "domain $domain\n";
    print RC "search $domain\n";
    print RC "nameserver $bossnode_ip\n";
    close(RC);
1078

1079
  skipsetup:
1080 1081 1082 1083 1084 1085
    #
    # Hmm, need to run this at startup though.
    # 
    mysystem("echo '/usr/local/etc/emulab/rc/rc.inelab' ".
	     "   >> /etc/rc.local");

1086 1087 1088
    return
	if ($NOSETUP);

1089 1090 1091 1092 1093 1094 1095 1096 1097
    #
    # Remove source code from ops so that mere users do not get access to it.
    # Something to do with licensing ...
    #
    mysystem("cp -p ${TBDIR}/testbed/src/testbed/defs-elabinelab ".
	     "      ${TBDIR}/testbed/src");
    mysystem("rm -rf ${TBDIR}/testbed/src/testbed");
    mysystem("rm -rf ${TBDIR}/testbed/obj/testbed");

1098 1099 1100 1101 1102 1103 1104
    #
    # Copy the mirror tree into place. Do not use rsync.
    #
    if (0 && -e "${TBDIR}/mirror") {
	print "Copying mirror tree into place\n";
	mysystem("cp -Rfp ${TBDIR}/mirror/ /");
    }
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
}

sub SetupBossNode()
{
    print "Setting up a Boss node ...\n";
    $TBDIR = "/usr";

    #
    # Create a ${TBDIR}/testbed from the extra slice and put everything there.
    # 
    mysystem("mkdir ${TBDIR}/testbed")
	if (! -d "${TBDIR}/testbed");
    mysystem("$BINDIR/mkextrafs.pl -f ${TBDIR}/testbed");
    mysystem("mkdir ${TBDIR}/testbed/src");
    mysystem("mkdir ${TBDIR}/testbed/obj");

1121
    GetEmulabSource("${TBDIR}/testbed/src");
1122 1123

    print "Copying over initial dbstate from /proj\n";
1124 1125 1126 1127 1128 1129 1130 1131
    my $expdir = "/proj/$pid/exp/$eid";
    my $stuffdir = "${TBDIR}/testbed/stuff";
    mysystem("mkdir $stuffdir");
    mysystem("cp -fp $expdir/dbstate.tar.gz  $stuffdir");
    mysystem("cp -fp $expdir/outer_db_schema $stuffdir");

    if (!$NOSETUP) {
	print "Check for db schema mismatch before we go any further\n";
Russ Fish's avatar
Russ Fish committed
1132
	my $testbed_srcdir = "${TBDIR}/testbed/src/testbed";
1133 1134 1135 1136 1137
	my $schemadiff     = "$testbed_srcdir/utils/schemadiff";
	my $master_schema  = "$testbed_srcdir/sql/database-create.sql";
	my $outer_schema   = "$stuffdir/outer_db_schema";
	mysystem("$schemadiff -st $master_schema $outer_schema");
    }
1138 1139

    # Copy over creators ssl certificate for XMLRPC. See below.
1140
    mysystem("cp -fp ~${creator}/.ssl/emulab.pem $stuffdir");
1141 1142 1143 1144 1145

    #
    # 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).
    # 
1146
    mysystem("echo '${outer_bossip}' > $ETCDIR/outer_bossnode");
1147
    mysystem("cp -p $BOOTDIR/routerip $ETCDIR/outer_router");
1148
    mysystem("cp -p $BOOTDIR/myip $ETCDIR/outer_ipaddr");
1149

1150 1151 1152 1153 1154 1155 1156 1157 1158
    #
    # Need outer ip and netmask for hardwired config below.
    #
    if (! -e "$BOOTDIR/myip") {
	SetupFatal("$BOOTDIR/myip does not exist!");
    }
    my $outer_ip = `cat $BOOTDIR/myip`;
    chomp($outer_ip);
    
1159 1160 1161 1162 1163 1164 1165 1166 1167
    #
    # And we need the name of the control interface for natd below.
    #
    if (! -e "$BOOTDIR/controlif") {
	SetupFatal("$BOOTDIR/controlif does not exist!");
    }
    my $outer_controlif = `cat $BOOTDIR/controlif`;
    chomp($outer_controlif);

1168 1169 1170 1171 1172
    #
    # We also need the hardwired config for the inner control network.
    # Major kludge; should get it from tmcd data.
    #
    my @ifacelist;
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
    my $inner_controlif;
    my $inner_ip;
    my $inner_netmask;

    if (! $SINGLE_CONTROLNET) {
	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};
1184 1185
    }

1186 1187 1188 1189 1190
    #
    # Run the prepare script to clear out the current accounts and such.
    # From this point on will need to log in as root,
    #
    print "Clearing out existing accounts and such\n";
1191
    mysystem("$BINDIR/prepare -N");
1192 1193 1194 1195 1196 1197
  
    #
    # Remove the outer testbed startup script.
    #
    mysystem("rm -f /usr/local/etc/rc.d/testbed.sh");

1198 1199 1200
    #
    # And clear some other stuff.
    # 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1201 1202
    mysystem("rm -rf /usr/testbed/lib");
    mysystem("rm -rf /usr/testbed/bin");
1203 1204
    unlink("/etc/rc.conf.d/dhclient")
	if (-e "/etc/rc.conf.d/dhclient");
1205 1206
    unlink("/etc/rc.d/netif-emulab")
	if (-e "/etc/rc.d/netif-emulab");
1207

1208 1209 1210 1211 1212 1213 1214
    #
    # Create a bigger /var/db/mysql (before installing mysql!)
    #
    mysystem("mkdir /var/db/mysql")
	if (! -d "/var/db/mysql");
    mysystem("$BINDIR/mkextrafs.pl -f -s 2 /var/db/mysql");

1215 1216 1217
    goto skippkg
	if ($NOSETUP);

1218 1219 1220 1221
    #
    # Do this as a separate step cause we need the NFS mounts, but
    # must do the unmounts before running ops-install. 
    # 
1222 1223 1224
    if (!$emulabconfig{BOSS_PKG_DIR} || !$emulabconfig{BOSS_PKG}) {
	SetupFatal("Could not get package info from Emulab!");
    }
1225
    print "Removing conflicting packages.\n";
1226 1227
    mysystem("pkg_delete -r -x mysql-client")
	if (-e "/usr/local/bin/mysql");
1228
    
1229
    print "Installing the boss metaport.\n";
1230 1231 1232

    # Make sure /usr/ports is not a symlink to RO shared space
    if (-l "/usr/ports") {
Mike Hibler's avatar
Mike Hibler committed
1233
	if (!unlink("/usr/ports")) {
1234 1235 1236 1237 1238 1239
	    print "WARNING: /usr/ports is a symlink, port install may fail\n";
	} else {
	    mysystem("mkdir /usr/ports");
	}
    }

1240
    $ENV{"PKG_PATH"} = $emulabconfig{BOSS_PKG_DIR};
1241
    mysystem("pkg_add -f $emulabconfig{BOSS_PKG} >/tmp/perrs 2>&1");
1242

1243
  skippkg:
1244 1245 1246 1247 1248
    #
    # We no longer need anything from NFS, and we need to unmount everything
    # so we can mount new NFS filesystems in their proper places. 
    # 
    mysystem("umount -A -t nfs");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258

    #
    # Lets mount the package dir so that we can pass off some stuff to
    # the install scripts.
    #
    if (! -d "/packages") {
	mysystem("mkdir /packages");
    }
    mysystem("mount ${fsname}:" . $emulabconfig{BOSS_PKG_DIR} . " /packages");

1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
    #
    # Need to create an /etc/rc.conf that is more suitable for boss.
    # I took most of this from our real ops node. It will be modified
    # by the ops-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 "kern_securelevel_enable=\"NO\"\n";
    print RC "sendmail_enable=\"YES\"\n";
    print RC "sshd_enable=\"YES\"\n";

    print RC "ntpdate_enable=\"YES\"\n";
    # Points to outer boss
1274
    print RC "ntpdate_flags=\"${outer_bossip}\"\n";
1275 1276 1277
    print RC "linux_enable=\"YES\"\n";
    print RC "accounting_enable=\"YES\"\n";

1278 1279
    print RC "rpcbind_enable=\"YES\"\n";
    print RC "mountd_enable=\"YES\"\n";
1280 1281 1282 1283
    print RC "nfs_server_enable=\"YES\"\n";
    print RC "nfs_server_flags=\"-u -t -n 8\"\n";
    print RC "nfs_client_enable=\"YES\"\n";

1284
    print RC "network_interfaces=\"$outer_controlif\"\n";