ops-install.in 45.4 KB
Newer Older
1 2 3 4
#!/usr/bin/perl -w

#
# EMULAB-COPYRIGHT
5
# Copyright (c) 2003-2010 University of Utah and the Flux Group.
6 7 8 9
# All rights reserved.
#

#
Robert Ricci's avatar
Robert Ricci committed
10
# ops-install - Script to do the initial install of an ops node
11 12 13 14 15
#
# The main things it does not do yet:
# * Figure out where to put directories such as /users /proj - they must
#   already exist
# * Fill out mailing list files - presumably, it's easier to just get the
16
#   User to edit them himself
17 18 19 20 21 22 23
#

#
# Configure variables
#
my $PREFIX = '@prefix@';

Robert Ricci's avatar
Robert Ricci committed
24
my @MAILING_LISTS = ("@TBOPSEMAIL@","@TBLOGSEMAIL@","@TBWWWEMAIL@",
25
    "@TBAPPROVALEMAIL@","@TBAUDITEMAIL@","@TBSTATEDEMAIL@",
26
    "@TBTESTSUITEEMAIL@", "@TBERRORSEMAIL@", "@TBAUTOMAILEMAIL@");
Robert Ricci's avatar
Robert Ricci committed
27

28

29 30 31 32 33 34
my $OURDOMAIN   = '@OURDOMAIN@';
my $USERNODE    = '@USERNODE@';
my $FSNODE      = '@FSNODE@';
my $BOSSNODE    = '@BOSSNODE@';
my $BOSSNODE_IP = '@BOSSNODE_IP@';
my $USERNODE_IP = '@USERNODE_IP@';
35
my $FSNODE_IP   = '@FSNODE_IP@';
36
my $LOGFACIL    = '@TBLOGFACIL@';
37
my $TBOPSEMAIL  = '@TBOPSEMAIL@';
38
my $ELABINELAB  = @ELABINELAB@;
39
my $WINSUPPORT  = @WINSUPPORT@;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
40
my $MAILMANSUPPORT = @MAILMANSUPPORT@;
41
my $CVSSUPPORT  = @CVSSUPPORT@;
42
my $BUGDBSUPPORT= @BUGDBSUPPORT@;
43
my $WIKISUPPORT = @WIKISUPPORT@;
44
my $QUOTA_FSLIST= '@FS_WITH_QUOTAS@';
45
my $ETCDIR      = "$PREFIX/etc";
46
my $LIBDIR      = "$PREFIX/lib";
47
my $SCRATCHDIR =  '@FSDIR_SCRATCH@';
Robert Ricci's avatar
Robert Ricci committed
48 49 50
my $OUTER_BOSS = '@OUTERBOSS_NODENAME@';
if ($OUTER_BOSS eq '')
    { $OUTER_BOSS = "www.emulab.net"; }
51 52 53 54 55 56 57 58 59

#
# Fixed paths for clients
#
my $PROJROOT    = "@PROJROOT_DIR@";
my $GROUPROOT   = "@GROUPSROOT_DIR@";
my $USERROOT    = "@USERSROOT_DIR@";
my $SCRATCHROOT	= "@SCRATCHROOT_DIR@";
my $SHAREROOT	= "@SHAREROOT_DIR@";
60
my $ELVIN_COMPAT= @ELVIN_COMPAT@;
61

62 63 64
# True if we are also the FS node
my $ISFS	= ($USERNODE eq $FSNODE) ? 1 : 0;

65 66 67 68
# For /share export below.
my $CONTROL_NETWORK = "@CONTROL_NETWORK@";
my $CONTROL_NETMASK = "@CONTROL_NETMASK@";

69 70 71
# Should be configure variable
my $TBADMINGID  = 101;

Mike Hibler's avatar
Mike Hibler committed
72 73 74
#
# XXX temporary for perl DBD mysql access
my $P5DBD_PKG	  = "p5-DBD-mysql50-3.0002";
75 76
# XXX temporary until fix dependencies in emulab-ops package
my $PYM2_PKG	  = "py25-m2crypto-0.19.1";
77 78
# XXX temporary until someone extracts their head from the dark regions
my $EASYINSTALL	  = "/usr/local/bin/easy_install";
Mike Hibler's avatar
Mike Hibler committed
79

80
#
Robert Ricci's avatar
Robert Ricci committed
81
# Allow this to work if the library is left in the source directory
82
#
Robert Ricci's avatar
Robert Ricci committed
83 84 85 86
use lib '@srcdir@';
   
use English;
use libinstall;
87 88 89 90 91 92
use Getopt::Std;

#
# Handle command-line options
#
sub usage {
93 94 95
    print "Usage: ops-install [-b] [-p packagedir] [-s] " .
	"[-P ops-portname] [-F fs-portname]\n";
    print "  Required: -p (for binary packages) or -s (for source makes.)\n";
96 97 98
    exit(1);
}

99
# Version of FreeBSD.
100 101 102 103 104
my $FBSD_MAJOR = 4;
my $FBSD_MINOR = 10;
if (`uname -r` =~ /^(\d+)\.(\d+)/) {
    $FBSD_MAJOR = $1;
    $FBSD_MINOR = $2;
105 106 107 108 109
}
else {
    die("Could not determine what version of FreeBSD you are running!\n");
}

110
#
111 112
# The meta-ports (name and version) that drag in all the dependancies for
# an ops/fs node. These are OS dependent as we upgrade.
113
#
114 115 116
my $OPS_PORT = "emulab-ops-1.4"; 
my $FS_PORT = "emulab-fs-1.4";
if ($FBSD_MAJOR > 4) {
117 118 119 120
    if ($FBSD_MAJOR > 6) {
	$OPS_PORT = "emulab-ops-3.0";
	$FS_PORT = "emulab-fs-3.0";
    } elsif ($FBSD_MAJOR == 6 && $FBSD_MINOR > 2) {
121 122 123 124 125 126 127
	$OPS_PORT = "emulab-ops-2.1";
	$FS_PORT = "emulab-fs-2.1";
    } else {
	$OPS_PORT = "emulab-ops-2.0";
	$FS_PORT = "emulab-fs-2.0";
    }
}
128
my $PHP4_PORT = "php4-extensions-1.0";
129

130
my $packagedir = "";
131
my $batchmode  = 0;
132
my $domakes  = 0;
133
my $password;
134
my %opts;
135
if (! getopts("P:p:bsw:F:", \%opts)) {
136 137 138 139
    usage();
}
if (defined($opts{p})) {
    $packagedir = $opts{p};
140
}
141
if (defined($opts{b})) {
142 143
    $batchmode = 1;
}
144 145 146
if (defined($opts{s})) {
    $domakes = 1;
}
147 148 149
if (defined($opts{P})) {
    $OPS_PORT = $opts{P};
}
150 151 152 153 154 155
if (defined($opts{F})) {
    $FS_PORT = $opts{F};
}
if (defined($opts{w})) {
    $password = $opts{w};
}
156 157 158 159 160 161 162 163 164
# Don't just charge into making ports from source by default.
if ($packagedir eq "" and $domakes eq 0) {
    print "At least one of -p and -s must be given.\n";
    usage();
}
if ($packagedir ne "" and $domakes eq 1) {
    print "Only one of -p and -s can be given.\n";
    usage();
}
165 166 167
if (@ARGV) {
    usage();
}
168

169 170 171 172 173 174 175 176
#
# Figure out which directory we live in, so that some stages can do thing
# relative to it.
#
my $OBJDIR = `/usr/bin/dirname $0`;
chomp $OBJDIR;
my $TOP_OBJDIR = "$OBJDIR/..";

177
#
Robert Ricci's avatar
Robert Ricci committed
178
# Some programs we use
179
#
Robert Ricci's avatar
Robert Ricci committed
180 181
my $CHGRP      = "/usr/bin/chgrp";
my $CHMOD      = "/bin/chmod";
182
my $CHOWN      = "/usr/sbin/chown";
Robert Ricci's avatar
Robert Ricci committed
183
my $PW         = "/usr/sbin/pw";
184
my $PATCH      = "/usr/bin/patch";
Robert Ricci's avatar
Robert Ricci committed
185
my $NEWALIASES = "/usr/bin/newaliases";
186
my $SH         = "/bin/sh";
187
my $PKG_ADD    = "/usr/sbin/pkg_add";
Mike Hibler's avatar
Mike Hibler committed
188
my $PKG_DEL    = "/usr/sbin/pkg_delete";
189
my $PWD        = "/bin/pwd";
190
my $CP         = "/bin/cp";
191
my $MV         = "/bin/mv";
192
my $ENV        = "/usr/bin/env";
193
my $MOUNT      = "/sbin/mount";
194 195
my $TAR	       = "/usr/bin/tar";
my $MD5	       = "/sbin/md5";
196 197

#
Robert Ricci's avatar
Robert Ricci committed
198
# Some files we edit/create
199
#
Robert Ricci's avatar
Robert Ricci committed
200
my $RCCONF          = "/etc/rc.conf";
201
my $HOSTS           = "/etc/hosts";
202
my $FSTAB           = "/etc/fstab";
Robert Ricci's avatar
Robert Ricci committed
203 204
my $RCLOCAL         = "/etc/rc.local";
my $RCCAPTURE       = "$PREFIX/etc/rc.capture";
Robert Ricci's avatar
Robert Ricci committed
205 206
my $LOCAL_HOSTNAMES = "/etc/mail/local-host-names";
my $ALIASES_FILE    = "/etc/mail/aliases";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
207
my $SENDMAIL_CF     = "/etc/mail/sendmail.cf";
Robert Ricci's avatar
Robert Ricci committed
208 209 210 211 212
my $EXPORTS_FILE    = "/etc/exports";
my $EXPORTS_HEAD    = "$EXPORTS_FILE.head";
my $SYSLOG_CONF     = "/etc/syslog.conf";
my $NEWSYSLOG_CONF  = "/etc/newsyslog.conf";
my $SUDOERS         = "/usr/local/etc/sudoers";
213
my $SSHD_CONFIG     = "/etc/ssh/sshd_config";
214
my $CRONTAB         = "/etc/crontab";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
215
my $AUTHKEYS	    = "/root/.ssh/authorized_keys";
Kirk Webb's avatar
 
Kirk Webb committed
216 217
my $SMBCONF_FILE    = "/usr/local/etc/smb.conf";
my $SMBCONF_HEAD    = "$SMBCONF_FILE.head";
218 219
my $APACHE_ETCDIR   = "/usr/local/etc/apache";
my $HTTPD_CONF      = "$APACHE_ETCDIR/httpd.conf";
220
my $WWWDIR          = "/usr/local/www/data";
221 222 223 224 225 226 227 228

# For installing mysqld
my $MYSQLADMIN      = "/usr/local/bin/mysqladmin";
my $MYSQLSHOW       = "/usr/local/bin/mysqlshow";
my $MYSQLDUMP       = "/usr/local/bin/mysqldump";
my $MYSQLINSTALL    = "/usr/local/bin/mysql_install_db";
my $MYSQLDBDIR      = "/var/db/mysql";
my $MYSQL_LOGDIR    = "$LOGDIR/mysql";
229 230

#
Robert Ricci's avatar
Robert Ricci committed
231
# Some directories we care about
232
#
233 234 235 236
my $LIST_DIR      = "/etc/mail/lists";
my $TIPLOG_DIR    = "/var/log/tiplogs";
my $PORTSMISCDIR  = "$PORTSDIR/misc";
my $SRCDIR        = '@srcdir@';
237 238

#
Robert Ricci's avatar
Robert Ricci committed
239
# And some lists that we use
240
#
241 242
my @LOCAL_HOSTS        = ($OURDOMAIN,$BOSSNODE,$USERNODE,$FSNODE);
my @LOGFILES           = ("/var/log/logins","/var/log/tiplogs/capture.log",
243 244
    "/var/log/mountd.log", "$LOGDIR/pubsubd.log", "$LOGDIR/elvin_gateway.log");

245 246
my @LOCAL_MAILING_LISTS = grep(/$OURDOMAIN$/,@MAILING_LISTS);
my @MAILING_LIST_NAMES  = map { /^([\w-]+)\@/ } @LOCAL_MAILING_LISTS;
Robert Ricci's avatar
Robert Ricci committed
247

248 249 250
my @TESTBED_DIRS       = ([$PREFIX, "0775"], [$USERROOT, "0755"],
			  [$PROJROOT, "0755"], [$GROUPROOT, "0755"],
			  [$SHAREROOT, "0775"]);
251

252 253 254 255 256 257
my @MOUNTPOINTS        = ($USERROOT, $PROJROOT, $GROUPROOT, $SHAREROOT);

if ($SCRATCHDIR) {
    push(@TESTBED_DIRS, [$SCRATCHROOT, "0755"]);
    push(@MOUNTPOINTS, $SCRATCHROOT);
}
258

259 260 261
#
# A few files we have to deal with
#
262
my $M2CRYPTO_PATCH  = "$TOP_SRCDIR/patches/m2crypto.patch";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
263
my $MAILMAN_PATCH   = "$TOP_SRCDIR/patches/mailman.patch";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
264
my $IDENTPUB        = "$TOP_SRCDIR/install/identity.pub";
265

266 267 268 269
#
# List of names that goes into $HOSTS and which must resolve.
# 
my @OPS_NAMES = ($USERNODE, "users", "ops");
270 271 272
if ($ISFS) {
    push(@OPS_NAMES, "fs");
}
273

274
#
Robert Ricci's avatar
Robert Ricci committed
275
# Make sure they know what they're getting into...
276
#
277 278 279 280
if (! $batchmode) {
    print STDERR
	"WARNING: This script is ONLY intended to be run on a machine\n";
    print STDERR
281
	"that is being set up as a dedicated ops or ops+fs node. Continue? [y/N] ";
282 283 284
    my $response = <>;
    die "Installation aborted!\n" unless ($response =~ /^y/i);
}
285

Robert Ricci's avatar
Robert Ricci committed
286 287
if ($UID != 0) {
    die "This script must be run as root.\n";
288 289 290
}

#
Robert Ricci's avatar
Robert Ricci committed
291
# The phases are fairly self-explanatory
292
#
293 294 295 296 297 298 299
Phase "sperl", "Checking for setuid perl", sub {
    if (ExecQuiet("$PKG_INFO -L -x perl-5 | fgrep -q -s sperl") == 0) {
	PhaseSkip("Perl is okay");
    }
    PhaseFail("setuid perl is not set up properly. Read the wiki!");
};

300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
Phase "usersgroups", "Creating users and groups", sub {
    Phase "tbadmin", "Creating tbadmin group", sub {
	if (getgrnam("tbadmin")) {
	    PhaseSkip("tbadmin group already exists");
	}
	ExecQuietFatal("$PW groupadd tbadmin -g $TBADMINGID");
    };
    # Added next two cause the mysql package does not do this (port does).
    Phase "mysqlgroup", "Creating mysql group", sub {
	if (getgrnam("mysql")) {
	    PhaseSkip("mysql group already exists");
	}
	ExecQuietFatal("$PW groupadd mysql -g 88");
    };
    Phase "mysqluser", "Creating mysql user", sub {
	if (getpwnam("mysql")) {
	    PhaseSkip("mysql user already exists");
	}
	ExecQuietFatal("$PW useradd mysql -g 88 -g 88 -h - ".
		       "-d $MYSQLDBDIR -s /sbin/nologin -c 'MySQL Daemon'");
    };
    ExecQuietFatal("$CHOWN mysql:mysql $MYSQLDBDIR")
	if (-e $MYSQLDBDIR);
Robert Ricci's avatar
Robert Ricci committed
323 324 325
};

Phase "dirs", "Setting directory permissions", sub {
Robert Ricci's avatar
Robert Ricci committed
326 327
    foreach my $dirref (@TESTBED_DIRS) {
	my ($dir, $newmode) = @$dirref;
Robert Ricci's avatar
Robert Ricci committed
328 329 330 331
	Phase $dir, $dir, sub {
	    if (!-d $dir) {
		PhaseFail("Directory $dir does not exist");
	    }
Robert Ricci's avatar
Robert Ricci committed
332 333 334 335
	    # Use the real path, to avoid symlink problems
	    my $realdir = `realpath $dir`;
	    chomp $realdir;
	    my ($mode,$group) = (stat($realdir))[2,5];
Robert Ricci's avatar
Robert Ricci committed
336 337
	    # Fix up the mode (strip file type)
	    $mode = $mode & 0777;
Robert Ricci's avatar
Robert Ricci committed
338
	    if ($mode == eval $newmode && $group eq getgrnam("tbadmin")) {
Robert Ricci's avatar
Robert Ricci committed
339 340
		PhaseSkip("Already done");
	    }
Robert Ricci's avatar
Robert Ricci committed
341 342
	    ExecQuietFatal("$CHGRP tbadmin $realdir");
	    ExecQuietFatal("$CHMOD $newmode $realdir");
Robert Ricci's avatar
Robert Ricci committed
343
	};
344
    }
Robert Ricci's avatar
Robert Ricci committed
345
};
346

347
Phase "ports", "Installing ports", sub {
348
    Phase "packages", "Installing packages", sub {
349 350 351 352 353 354 355 356 357
	Phase "main", "Installing main package", sub {
	    if (!ExecQuiet("$PKG_INFO -e $OPS_PORT")) {
		PhaseSkip("Package already installed");
	    }
	    if (!$packagedir) {
		PhaseSkip("No package directory provided");
	    }
	    ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $OPS_PORT");
	};
358
	if ($FBSD_MAJOR > 4) {
359 360 361 362 363 364 365 366 367 368
	    Phase "php4", "Installing php4 package", sub {
		if (!ExecQuiet("$PKG_INFO -e $PHP4_PORT")) {
		    PhaseSkip("Package already installed");
		}
		if (!$packagedir) {
		    PhaseSkip("No package directory provided");
		}
		ExecQuietFatal("$ENV PKG_PATH=$packagedir ".
			       "     $PKG_ADD $PHP4_PORT");
	    };
369
	}
370 371
	# XXX Also temporary
	Phase "pubsub", "Installing pubsub package", sub {
372 373 374
	    my $pspkg = $ELVIN_COMPAT ? "pubsub-elvincompat" : "pubsub";
	    if (!ExecQuiet("$PKG_INFO -x $pspkg")) {
		PhaseSkip("$pspkg already installed");
375
	    }
376
	    my $pname = GetPackage($pspkg, $packagedir);
377 378
	    ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $pname");
	};
Mike Hibler's avatar
Mike Hibler committed
379
	# XXX Ditto
380
	if ($FBSD_MAJOR > 6 || ($FBSD_MAJOR == 6 && $FBSD_MINOR > 2)) {
Mike Hibler's avatar
Mike Hibler committed
381 382 383 384 385 386 387 388 389 390 391 392 393
	    Phase "p5-DBD-mysql50", "Installing old Perl Mysql package", sub {
		my $pname = `$PKG_INFO -E 'p5-DBD-mysql50-*' 2>/dev/null`;
		chomp($pname);
		if ($pname eq $P5DBD_PKG) {
		    PhaseSkip("p5-DBD-mysql50 already up to date");
		}
		if (!$packagedir) {
		    PhaseSkip("No package directory provided");
		}
		ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_DEL -f $pname")
		    if ($pname);
		ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $P5DBD_PKG");
	    };
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
	    # XXX cannot seem to get these dependencies into emulab-boss
	    if ($FBSD_MAJOR > 6) {
		Phase "py-m2crypto", "Installing python m2crypto package", sub {
		    my $pname = `$PKG_INFO -E 'py25-m2crypto-*' 2>/dev/null`;
		    chomp($pname);
		    if ($pname eq $PYM2_PKG) {
			PhaseSkip("py25-m2crypto already up to date");
		    }
		    if (!$packagedir) {
			PhaseSkip("No package directory provided");
		    }
		    ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_DEL -f $pname")
			if ($pname);
		    ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $PYM2_PKG");
		};
	    }
Mike Hibler's avatar
Mike Hibler committed
410
	}
411
    };
412 413 414 415 416 417 418 419 420 421 422 423
    Phase "fs-packages", "Installing FS packages", sub {
	if (!$ISFS) {
	    PhaseSkip("Not FS Node");
	}
	if (!ExecQuiet("$PKG_INFO -e $FS_PORT")) {
	    PhaseSkip("FS ports already installed");
	}
	if (!$packagedir) {
	    PhaseSkip("No package directory provided");
	}
	ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $FS_PORT");
    };
Leigh B. Stoller's avatar
Leigh B. Stoller committed
424 425
    if ($MAILMANSUPPORT) {
	Phase "mailman", "Installing Mailman package", sub {
426
	    if (!ExecQuiet("$PKG_INFO -x -E mailman")) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
427 428 429 430 431
		PhaseSkip("Mailman package already installed");
	    }
	    if (!$packagedir) {
		PhaseSkip("No package directory provided");
	    }
432
	    my $pname = GetPackage("mailman", $packagedir);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
433 434 435
	    ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $pname");
	};
    }
436 437 438
    if ($CVSSUPPORT) {
	Phase "cvsd", "Installing cvsd package", sub {
	    PhaseSkip("cvsd not supported on ops")
439
		if ($FBSD_MAJOR < 6);
440

441
	    if (!ExecQuiet("$PKG_INFO -x -E cvsd")) {
442 443 444 445 446
		PhaseSkip("cvsd package already installed");
	    }
	    if (!$packagedir) {
		PhaseSkip("No package directory provided");
	    }
447
	    my $pname = GetPackage("cvsd", $packagedir);
448 449 450
	    ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $pname");
	};
    }
451 452 453
    if ($BUGDBSUPPORT) {
	Phase "flyspray", "Installing flyspray package support", sub {
	    PhaseSkip("flyspray not supported on ops")
454
		if ($FBSD_MAJOR < 6);
455

456
	    if (!ExecQuiet("$PKG_INFO -x -E adodb")) {
457 458 459 460 461
		PhaseSkip("adodb package already installed");
	    }
	    if (!$packagedir) {
		PhaseSkip("No package directory provided");
	    }
462
	    my $pname = GetPackage("adodb", $packagedir);
463 464 465
	    ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $pname");
	};
    }
466
    PhaseSkip("Package directory provided; not installing from sources")
Leigh B. Stoller's avatar
Leigh B. Stoller committed
467 468
	if ($packagedir);
    
469
    Phase "pcopy", "Copying ports into place", sub {
470
	DoneIfExists("$PORTSMISCDIR/emulab-ops");
471 472
	ExecQuietFatal("$SH $SRCDIR/ports/ports-install");
    };
473 474
    my $pwd = `$PWD`;
    chomp $pwd;
475
    Phase "pinstall", "Installing ports (may take a while)", sub {
476
	if (!ExecQuiet("$PKG_INFO -e $OPS_PORT")) {
477 478 479 480 481 482
	    PhaseSkip("Ports already installed");
	}

	#
	# This port is dead-simple, so it's safe to do it from this script
	#
483 484
	chdir "$PORTSMISCDIR/emulab-ops" or
		PhaseFail "Unable to change to $PORTSMISCDIR/emulab-ops: $!";
485
	ExecQuietFatal("make -DBATCH install");
486
    };
487 488 489 490 491 492 493 494 495 496 497
    Phase "fs-pinstall", "Installing FS ports (may take a while)", sub {
	if (!$ISFS) {
	    PhaseSkip("Not FS Node");
	}
	if (!ExecQuiet("$PKG_INFO -e $FS_PORT")) {
	    PhaseSkip("Ports already installed");
	}
	chdir "$PORTSMISCDIR/emulab-fs" or
	    PhaseFail "Unable to change to $PORTSMISCDIR/emulab-fs: $!";
	ExecQuietFatal("make -DBATCH install");
    };
Leigh B. Stoller's avatar
Leigh B. Stoller committed
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
    Phase "php4-pinstall", "Installing PHP4 ports (may take a while)", sub {
	if (!ExecQuiet("$PKG_INFO -e $PHP4_PORT")) {
	    PhaseSkip("Ports already installed");
	}
	chdir "$PORTSMISCDIR/emulab-php4" or
	    PhaseFail "Unable to change to $PORTSMISCDIR/emulab-php4: $!";
	ExecQuietFatal("make -DBATCH install");
    };
    if ($MAILMANSUPPORT) {
	Phase "mailman-pinstall", "Installing mailman ports", sub {
	    if (!ExecQuiet("$PKG_INFO -x -e mailman")) {
		PhaseSkip("Ports already installed");
	    }
	    chdir "$PORTSMISCDIR/emulab-mailman" or
		PhaseFail("Unable to change to ".
			  "$PORTSMISCDIR/emulab-mailman: $!");
	    ExecQuietFatal("make -DBATCH install");
	};
    }
517
    chdir $pwd;
518 519
};

520 521
# XXX Temporary.
Phase "portfixup", "Fixing up packages", sub {
522
    Phase "rsync", "Looking for rsync and installing", sub {
523 524 525
	if (!ExecQuiet("$PKG_INFO -x rsync")) {
	    PhaseSkip("rsync already installed");
	}
526 527
	my $pname = GetPackage("rsync", $packagedir);
	ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $pname");
528
    };
529 530
    if ($WINSUPPORT) {
	Phase "samba", "Looking for Samba and installing", sub {
531 532 533
	    if (!$ISFS) {
		PhaseSkip("Not FS Node");
	    }
534 535 536
	    if (!ExecQuiet("$PKG_INFO -x samba")) {
		PhaseSkip("samba already installed");
	    }
537 538
	    my $pname = GetPackage("samba", $packagedir);
	    ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $pname");
539 540
	};
	Phase "gcc30", "Looking for GCC 3.0 and installing", sub {
541
	    if ($FBSD_MAJOR > 4 ||
542
		!ExecQuiet("$PKG_INFO -x gcc30")) {
543
		PhaseSkip("GCC 3.0 or greater already installed");
544
	    }
545 546
	    my $pname = GetPackage("gcc30", $packagedir);
	    ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $pname");
547 548
	};
    }
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
    if ($FBSD_MAJOR > 6) {
	#
	# What a crock!  First, that the FreeBSD ports system
	# defaults to installing the zipped .egg files that have
	# to be unzipped per-user before use.  Second, that it
	# offers no easy way at package creation to override this.
	# Third, that there is no easy way that I could find in
	# the python eggs system to set a global cache directory
	# into which to unpack all eggs; you have to set
	# PYTHON_EGG_CACHE in the environment of every script.
	# Fourth, that the per-user default value might be in an
	# unwritable location.
	#
	# So, I am reduced to manually unpacking all .egg files
	# into the corresponding .egg directories after the
	# install!  Since this would totally screw any attempt
	# to update those packages, I just do it to the one
	# package that I know will fail otherwise.
	#
	Phase "m2crypto-egg", "Unpacking python m2crypto .egg", sub {
	    my $pydir = "/usr/local/lib/python2.5/site-packages";
Mike Hibler's avatar
Mike Hibler committed
570
	    my $egg = `ls -d $pydir/M2Crypto-0.19.1-py2.5-*.egg 2>/dev/null | tail -1`;
571 572 573 574 575 576 577 578 579 580
	    chomp($egg);
	    if (! -x $EASYINSTALL) {
		PhaseSkip("python easy_install missing");
	    }
	    if ($egg eq "") {
		PhaseSkip("py25-m2crypto egg not found");
	    }
	    if (-d "$egg") {
		PhaseSkip("py25-m2crypto egg already unpacked");
	    }
Mike Hibler's avatar
Mike Hibler committed
581 582 583 584 585 586
	    # XXX swig must be installed for easyinstall to exit correctly
	    Phase "swig", "Installing swig", sub {
		DoneIfPackageInstalled("swig");
		my $pname = GetPackage("swig", $packagedir);
		ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $pname");
	    };
587 588 589 590 591 592
	    ExecQuietFatal("mv $egg /var/tmp/");
	    $egg =~ s/$pydir//;
	    ExecQuietFatal("$EASYINSTALL -Z /var/tmp$egg");
	    ExecQuietFatal("mv /var/tmp$egg $pydir/$egg.bak");
	};
    }
593 594
};

595
Phase "patches", "Applying patches", sub {
596 597 598
    if ($FBSD_MAJOR < 7) {
	Phase "m2cryptopatch", "Patching m2crypto", sub {
	    my $patchfile = $M2CRYPTO_PATCH;
599

600 601 602 603 604 605 606 607 608 609 610 611
	    if (ExecQuiet("$PKG_INFO -I -x m2crypto | fgrep -q -s '0.17'") == 0) {
		$patchfile = "${patchfile}-0.17";
	    }
	    elsif (ExecQuiet("$PKG_INFO -I -x m2crypto | fgrep -q -s '0.13'") == 0) {
		$patchfile = "${patchfile}-0.13";
	    }
	    if (!ExecQuiet("$PATCH -C -f -l -R -p0 -i $patchfile")) {
		PhaseSkip("Patch already applied");
	    }
	    ExecQuietFatal("$PATCH -f -l -p0 -i $patchfile");
	};
    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
612 613 614 615 616
    if ($MAILMANSUPPORT) {
	Phase "mailmanpatch", "Patching mailman", sub {
	    my $patchfile = $MAILMAN_PATCH;
	
	    if (!ExecQuiet("$PATCH -C -f -l -R -p0 -i $patchfile")) {
617
		PhaseSkip("Patch already applied");
Leigh B. Stoller's avatar
Leigh B. Stoller committed
618 619 620 621
	    }
	    ExecQuietFatal("$PATCH -f -l -p0 -i $patchfile");
	};
    }
622 623
}; 

Robert Ricci's avatar
Robert Ricci committed
624 625 626
Phase "rc.conf", "Adding testbed content to rc.conf", sub {
    DoneIfEdited($RCCONF);
    AppendToFileFatal($RCCONF,
Robert Ricci's avatar
Robert Ricci committed
627
		      qq|sendmail_enable="YES"|,
628 629
		      qq|rpcbind_enable="YES"|,
		      qq|mountd_enable="YES"|,
Robert Ricci's avatar
Robert Ricci committed
630 631
		      qq|nfs_server_enable="YES"|,
		      qq|nfs_server_flags="-u -t -n 16"|,
632
		      qq|mountd_flags="-r -p 900"|,
633
		      (($ISFS && $WINSUPPORT) ? qq|smbd_enable="YES"| : ()),
634
		      qq|apache_enable="YES"|,
Mike Hibler's avatar
Mike Hibler committed
635
		      qq|syslogd_flags=""|,
636 637
		      ($CVSSUPPORT ? qq|cvsd_enable="YES"| : ()),
		      qq|pubsubd_flags="-T 10"|);
Robert Ricci's avatar
Robert Ricci committed
638
};
639

640
Phase "hosts", "Adding boss/ops/fs IP addresses to $HOSTS", sub {
641
    DoneIfEdited($HOSTS);
642 643 644 645 646 647 648 649
    # XXX get rid of any existing lines with boss/ops/fs
    if ($ELABINELAB) {
	my $dellist = "-e '/^${BOSSNODE_IP}/d' -e '/^${USERNODE_IP}/d'";
	if (!$ISFS) {
	    $dellist .= " -e '/^${FSNODE_IP}/d'";
	}
	ExecQuietFatal("sed -i.orig $dellist $HOSTS");
    }
650 651 652 653 654 655
    my $hstr = "${BOSSNODE_IP}\t${BOSSNODE} boss" .
	"\n${USERNODE_IP}\t@OPS_NAMES";
    if (!$ISFS) {
	$hstr .= "\n${FSNODE_IP}\t${FSNODE} fs";
    }
    AppendToFileFatal($HOSTS, $hstr);
656 657
};

658 659 660 661 662 663 664
Phase "resolve", "Checking to make sure names for boss/ops/fs resolve", sub {
    my @hnames = (@OPS_NAMES, $BOSSNODE, "boss");

    if (!$ISFS) {
	push @hnames, $FSNODE, "fs";
    }
    foreach my $name (@hnames) {
665 666
	Phase $name, $name, sub {
	    if (gethostbyname($name)) {
667
		PhaseSucceed("$name resolves");
668 669 670 671 672 673 674
	    } else {
		PhaseFail("$name does not resolve");
	    }
	};
    }
};

Robert Ricci's avatar
Robert Ricci committed
675 676 677 678 679 680 681 682 683 684
Phase "sendmail","Configuring sendmail", sub {
    Phase "localhosts", "Setting up $LOCAL_HOSTNAMES", sub {
	DoneIfExists($LOCAL_HOSTNAMES);
	CreateFileFatal($LOCAL_HOSTNAMES,@LOCAL_HOSTS);
    };
    Phase "maillists", "Setting up mailing lists", sub {
	Phase "listdir", "Creating $LIST_DIR", sub { 
	    DoneIfExists($LIST_DIR);
	    mkdir($LIST_DIR,0755) or
		PhaseFail("Unable to create $LIST_DIR: $!");
685 686
	    ExecQuietFatal("$CHGRP mailnull $LIST_DIR");
	    ExecQuietFatal("$CHMOD 750 $LIST_DIR");
Robert Ricci's avatar
Robert Ricci committed
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
	};
	Phase "listfiles", "Creating mailing list files", sub {
	    foreach my $list (@MAILING_LIST_NAMES) {
		Phase $list, $list, sub {
		    DoneIfExists("$LIST_DIR/$list");
		    CreateFileFatal("$LIST_DIR/$list");
		};
	    }
	};
	Phase "aliases", "Adding lists to $ALIASES_FILE", sub {
	    DoneIfEdited($ALIASES_FILE);
	    AppendToFileFatal($ALIASES_FILE,
		map("$_:\t:include:$LIST_DIR/$_",@MAILING_LIST_NAMES));
	};
	Phase "newaliases", "Running newaliases", sub {
702
	    PhaseSkip("No new aliases") unless @MAILING_LIST_NAMES;
Robert Ricci's avatar
Robert Ricci committed
703 704 705 706 707 708 709 710 711 712 713 714
	    PhaseSkip("No new aliases") if PhaseWasSkipped("aliases");
	    ExecQuietFatal($NEWALIASES);
	};
    };
};

Phase "exports", "Setting up exports", sub {
    Phase "ex.head", "Creating $EXPORTS_HEAD", sub {
	DoneIfExists($EXPORTS_HEAD);

	#
	# Figure out which of these directories are on the same
715 716
	# filesystems.  Note: we cannot do /share on the same exports line
	# as the other filesystems because of the RO mount below (trust me).
Robert Ricci's avatar
Robert Ricci committed
717
	#
718
	my @dirs = ('/var', $PREFIX);
719
	if ($ISFS) {
720
	    @dirs = (grep(!/^$SHAREROOT$/, @MOUNTPOINTS), @dirs);
721
	}
Robert Ricci's avatar
Robert Ricci committed
722 723 724 725 726 727 728 729 730 731 732 733 734 735
	@dirs = map {`realpath $_`} @dirs;
	chomp @dirs;
	my %filesystems;
	foreach my $dir (@dirs) {
	    my ($dev,@junk) = stat $dir;
	    push @{$filesystems{$dev}}, $dir;
	}

	#
	# Use that knowledge to create lines for /etc/exports.head
	#
	my @exports_lines;
	foreach my $key (keys %filesystems) {
	    push @exports_lines,
736 737
		join(" ",@{$filesystems{$key}}) .
		    "\t$BOSSNODE -maproot=root";
Robert Ricci's avatar
Robert Ricci committed
738 739
	}

740 741 742 743 744 745 746
	if ($ISFS) {
	    #
	    # /share is special. We want to export to boss read-write,
	    # but to the control network read-only.
	    #
	    my ($a,$b,$c,$d) =
		($CONTROL_NETWORK =~ /^(\d*)\.(\d*)\.(\d*)\.(\d*)/);
747
	    my $realdir = `realpath $SHAREROOT`;
748 749 750 751 752
	    chomp($realdir);
	    push(@exports_lines,
		 "$realdir\t$BOSSNODE -maproot=root");
	    push(@exports_lines,
		 "$realdir\t-network ${a}.${b}.${c} -mask $CONTROL_NETMASK ".
753
		 "-maproot=root -ro -alldirs");
754
	}
755

756 757 758 759 760
	#
	# Add localhost mount to proj/cvsrepos.
	#
	if ($CVSSUPPORT) {
	    my $pdir;
761
	    my $dfout = `df $PROJROOT | fgrep '/dev'`;
762
	    if ($?) {
763
		PhaseFail("'df $PROJROOT' failed!");
764 765 766 767 768
	    }
	    if ($dfout =~ /\s+([\/\w]*)$/) {
		$pdir = $1;
	    }
	    else {
769
		PhaseFail("Could not determine where $PROJROOT is mounted!");
770 771 772 773
	    }
	    push(@exports_lines, "$pdir\tlocalhost -alldirs");
	}

Robert Ricci's avatar
Robert Ricci committed
774 775 776 777 778 779 780
	#
	# Put them in exports.head, and copy that to /etc/exports
	#
	CreateFileFatal($EXPORTS_HEAD, @exports_lines);
	ExecQuietFatal("cp $EXPORTS_HEAD $EXPORTS_FILE");
    };

781
    # XXX Newhup
Robert Ricci's avatar
Robert Ricci committed
782 783 784 785 786 787
    Phase "mountd", "HUPing mountd", sub {
	PhaseSkip("No new exports file") if PhaseWasSkipped("ex.head");
	PhaseSkip("mountd not running") unless `ps -auxw | grep mountd | grep -v grep`;
	ExecQuietFatal("killall -HUP mountd");
    };
};
788

789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
Phase "NFSmounts", "Setting up NFS mounts", sub {
    if ($ISFS) {
	PhaseSkip("FSes are local");
    }

    Phase "mountpoints", "Creating mountpoints", sub {
	foreach my $dir (@MOUNTPOINTS) {
	    Phase $dir, $dir, sub {
		DoneIfExists($dir);
		mkdir $dir, 0777 or
		    PhaseFail("Unable to create $dir : $!");
	    };
	}
    };
    Phase "fstab", "Adding NFS mounts to $FSTAB", sub {
	DoneIfEdited($FSTAB);
Mike Hibler's avatar
Mike Hibler committed
805 806 807 808 809 810 811
	my $nfsopt = "nosuid";
	$nfsopt .= ",nodev"
	    if ($FBSD_MAJOR < 7);
	my @lines = ("$FSNODE:$USERROOT\t\t$USERROOT\tnfs\trw,$nfsopt\t0\t0",
		     "$FSNODE:$PROJROOT\t\t$PROJROOT\tnfs\trw,$nfsopt\t0\t0",
		     "$FSNODE:$GROUPROOT\t\t$GROUPROOT\tnfs\trw,$nfsopt\t0\t0",
		     "$FSNODE:$SHAREROOT\t\t$SHAREROOT\tnfs\trw,$nfsopt\t0\t0");
812 813
	if ($SCRATCHDIR) {
	    push(@lines,
Mike Hibler's avatar
Mike Hibler committed
814
		 "$FSNODE:$SCRATCHROOT\t\t$SCRATCHROOT\tnfs\trw,$nfsopt\t0\t0");
815 816 817
	}

	AppendToFileFatal($FSTAB, @lines);
818 819 820 821 822 823 824 825 826 827 828
    };
    Phase "mounts", "Mounting NFS filesystems", sub {
	foreach my $dir (@MOUNTPOINTS) {
	    Phase $dir, $dir, sub {
		DoneIfMounted($dir);
		ExecQuietFatal("$MOUNT -o '-R 1' $dir");
	    };
	}
    };
};

829 830 831
#
# Set up syslog
#
Robert Ricci's avatar
Robert Ricci committed
832 833 834 835 836 837 838 839 840 841 842
Phase "syslog", "Setting up syslog", sub {
    Phase "sysconf", "Editing $SYSLOG_CONF", sub {
	DoneIfEdited($SYSLOG_CONF);
	
	#
	# Can't just append to this file, unfortunately. Have to put some of
	# the lines in the middle of the file
	#
	open(SC,"+<$SYSLOG_CONF") or
	    PhaseFail("Unable to open $SYSLOG_CONF : $!");
	my @sc = <SC>;
843 844 845
	if (scalar(grep(/$LOGFACIL/, @sc)) != 0) {
	    PhaseFail("Testbed chosen facility $LOGFACIL already in use in /etc/syslog.conf!");
	}
Robert Ricci's avatar
Robert Ricci committed
846 847
	if (scalar(grep(/^cron/, @sc)) != 1) {
	    PhaseFail("Unable to find marker in /etc/syslog.conf!");
848 849
	}

Robert Ricci's avatar
Robert Ricci committed
850 851 852 853 854
	#
	# Clobber and re-write
	#
	seek(SC,0,0);
	truncate(SC,0);
855

Robert Ricci's avatar
Robert Ricci committed
856
	foreach my $line (@sc) {
857 858 859 860 861 862 863
	    #
	    # Modify the /var/log/messages line to exclude testbed stuff
	    #
	    my $pat = q(\s+/var/log/messages);
	    if ($line =~ /^[^#].*$pat/) {
		$line =~ s/($pat)/\;$LOGFACIL.none$1/;
	    }
864 865 866 867 868 869 870 871 872 873 874 875

	    #
	    # XXX don't send anything to logged in root users.
	    # Per-user linktest proxies run on ops as root in a "full"
	    # ssh ("-t -t") which appears as a login shell.  Thus the
	    # linktest output given to the user might include syslog
	    # messages.
	    #
	    if ($line =~ /root$/) {
		$line =~ s/^/#/;
	    }

Robert Ricci's avatar
Robert Ricci committed
876
	    print SC $line;
877 878 879 880

	    #
	    # Find the cron line, after which we place our auth.info line
	    #
Robert Ricci's avatar
Robert Ricci committed
881
	    if ($line =~ /^cron/) {
882
		print SC "# " . MAGIC_TESTBED_START() . "\n";
Robert Ricci's avatar
Robert Ricci committed
883
		print SC "auth.info\t\t\t\t\t/var/log/logins\n";
884
		print SC "# " . MAGIC_TESTBED_END() . "\n";
Robert Ricci's avatar
Robert Ricci committed
885 886
	    }
	}
887

Robert Ricci's avatar
Robert Ricci committed
888 889 890
	#
	# Put a few more lines at the end
	#
891
	print SC "# " . MAGIC_TESTBED_START() . "\n";
Robert Ricci's avatar
Robert Ricci committed
892 893 894 895
	print SC "!capture\n";
	print SC "*.*\t\t\t\t\t\t/var/log/tiplogs/capture.log\n";
	print SC "!mountd\n";
	print SC "*.*\t\t\t\t\t\t/var/log/mountd.log\n";
896
	print SC "!pubsubd\n";
897
	print SC "*.*\t\t\t\t\t\t${LOGDIR}/pubsubd.log\n";
898
	print SC "!elvin_gateway\n";
899
	print SC "*.*\t\t\t\t\t\t${LOGDIR}/elvin_gateway.log\n";
900
	print SC "# " . MAGIC_TESTBED_END() . "\n";
Robert Ricci's avatar
Robert Ricci committed
901 902 903 904 905 906 907 908
	close SC;
    };

    Phase "tiplog", "Creating $TIPLOG_DIR", sub {
	DoneIfExists($TIPLOG_DIR);
	mkdir($TIPLOG_DIR,0755) or PhaseFail("Unable to make $TIPLOG_DIR : $!");
    };
    
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
    Phase "logdir", "Creating log directory", sub {
	DoneIfExists($LOGDIR);
	mkdir $LOGDIR, 0775 or PhaseFail("Unable to create $LOGDIR : $!");
	ExecQuietFatal("$CHGRP tbadmin $LOGDIR");
	ExecQuietFatal("$CHMOD 775 $LOGDIR");
    };

    Phase "mysql-logdir", "Creating mysql log directory", sub {
	DoneIfExists($MYSQL_LOGDIR);
	mkdir $MYSQL_LOGDIR, 0775 or
	    PhaseFail("Unable to create $MYSQL_LOGDIR : $!");
	ExecQuietFatal("$CHOWN mysql:mysql $MYSQL_LOGDIR");
	ExecQuietFatal("$CHMOD 775 $MYSQL_LOGDIR");
    };

Robert Ricci's avatar
Robert Ricci committed
924 925 926 927 928
    Phase "logfiles", "Creating log files", sub {
	foreach my $logfile (@LOGFILES) {
	    Phase $logfile, $logfile, sub {
		DoneIfExists($logfile);
		CreateFileFatal($logfile);
929
		ExecQuietFatal("$CHGRP tbadmin $logfile");
Robert Ricci's avatar
Robert Ricci committed
930 931 932 933 934 935 936 937 938 939
		ExecQuietFatal("$CHMOD 640 $logfile");
	    };
	}
    };

    Phase "newsyslog", "Setting up $NEWSYSLOG_CONF", sub {
	DoneIfEdited($NEWSYSLOG_CONF);
	AppendToFileFatal($NEWSYSLOG_CONF,
	    "/var/log/logins\t\t\t\t640  7     200 *      Z",
	    "/var/log/mountd.log\t\t\t640  5     200 *      Z",
940 941
	    "$LOGDIR/pubsubd.log\t\t\t640  5     1000 *     Z",
	    "$LOGDIR/elvin_gateway.log\t\t\t640  5     1000 *     Z",
Robert Ricci's avatar
Robert Ricci committed
942 943 944 945
	    "/var/log/tiplogs/capture.log\t\t644  7     *    168   Z");
    };
};

946 947
Phase "cron", "Adding cron jobs", sub {
    Phase "crontab", "Editing $CRONTAB", sub {
948 949 950
	if ($QUOTA_FSLIST eq "") {
	    PhaseSkip("No filesystem quotas");
	}
951
	DoneIfEdited($CRONTAB);
952 953 954 955 956 957 958 959

	my @cronlist = ("0 \t6\t*\t*\t*\troot\t$PREFIX/sbin/quotamail");
	if ($WIKISUPPORT) {
	    push(@cronlist,
		 "*/15 \t*\t*\t*\t*\troot\t(cd /usr/local/www/data/twiki/bin;".
		 " ./mailnotify -q >> /var/tmp/mailnotify.log 2>&1)");
	}
	AppendToFileFatal($CRONTAB, @cronlist);
960 961 962 963 964 965 966
    };
    Phase "cronhup", "HUPing cron", sub {
	if (PhaseWasSkipped("crontab")) { PhaseSkip("No new crontab"); }
	HUPDaemon("cron");
    };
};

967
Phase "sudoers", "Editing $SUDOERS to allow wheel group", sub {
Robert Ricci's avatar
Robert Ricci committed
968
    DoneIfEdited($SUDOERS);
Russ Fish's avatar
Russ Fish committed
969 970 971
    AppendToFileFatal($SUDOERS,
		      "%wheel    ALL=(ALL) NOPASSWD: ALL",
		      "Defaults  logfile=/var/log/sudo.log");
Robert Ricci's avatar
Robert Ricci committed
972
};
973

974 975 976 977 978 979 980 981 982 983 984 985 986
Phase "samba", "Setting up Samba", sub {
    if (!$ISFS) {
	PhaseSkip("Not FS node");
    }
    if (!$WINSUPPORT) {
	PhaseSkip("Windows support not enabled");
    }
    Phase "smb.conf", "Installing smb.conf[.head]", sub {
	DoneIfEdited($SMBCONF_HEAD);
	ExecQuietFatal("$CP -pf $TOP_OBJDIR/install/smb.conf.head $SMBCONF_HEAD");
	AppendToFileFatal($SMBCONF_HEAD,
			  "# This file created by Emulab Control");
	ExecQuietFatal("$CP -pf $SMBCONF_HEAD $SMBCONF_FILE");
987
    };
988 989 990 991 992 993 994
    Phase "samba.sh", "Installing samba.sh", sub {
	DoneIfExists("$RCDIR/samba.sh");
	DoneIfDoesntExist("$RCDIR/samba.sh.sample");
	ExecQuietFatal("$MV -f $RCDIR/samba.sh.sample $RCDIR/samba.sh");
    };
    if ($ELABINELAB) {	
	Phase "starting", "Starting Samba", sub {
995 996 997 998 999 1000 1001 1002
	    my $sscript;
	    if (-x "$RCDIR/samba.sh") {
		$sscript = "samba.sh";
	    } elsif (-x "$RCDIR/samba") {
		$sscript = "samba";
	    } else {
		PhaseFail("No samba startup script!?");
	    }
1003
	    DoneIfExists("$VARRUN/smbd.pid");
1004
	    ExecQuietFatal("$RCDIR/$sscript start");
1005 1006 1007
	};
    }
};
1008

Robert Ricci's avatar
Robert Ricci committed
1009
Phase "ssh", "Allowing root ssh", sub {
Robert Ricci's avatar
Robert Ricci committed
1010 1011
    Phase "sshdconfig", "Permitting root login through ssh", sub {
	DoneIfEdited($SSHD_CONFIG);
1012 1013 1014 1015
	# modern versions of FBSD explicitly turn off proto 1 by default
	if ($FBSD_MAJOR > 6) {
	    ExecQuietFatal("sed -i.orig -e 's/Protocol/#Protocol/' $SSHD_CONFIG");
	}
1016 1017 1018
	AppendToFileFatal($SSHD_CONFIG,
			  "PermitRootLogin yes",
			  "Protocol 2,1");
Robert Ricci's avatar
Robert Ricci committed
1019 1020 1021 1022 1023 1024
    };
    Phase "dotssh", "Making root's .ssh directory", sub {
	DoneIfExists("/root/.ssh");
	mkdir("/root/.ssh",0700) or
	    PhaseFail("Unable to create /root/.ssh: $!");
    };
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
    Phase "authkeys", "Adding stub identity to root authorized_keys", sub {
	DoneIfEdited($AUTHKEYS);
	my $ident = `cat $IDENTPUB`;
	PhaseFail("Could not read $IDENTPUB")
	    if ($?);
	chomp($ident);
	if (! -e $AUTHKEYS) {
	    CreateFileFatal($AUTHKEYS);
	}
	AppendToFileFatal($AUTHKEYS,
			  "from=\"${BOSSNODE}\" $ident");
    };
Robert Ricci's avatar
Robert Ricci committed
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
};

Phase "capture", "Setting up capture", sub {
    Phase "rc.local", "Creating $RCLOCAL", sub {
	DoneIfExists($RCLOCAL);
	CreateFileFatal($RCLOCAL,
	    "if [ -f /etc/defaults/rc.conf ]; then",
	    "\t. /etc/defaults/rc.conf",
	    "fi",
	    "",
	    "if [ -x $RCCAPTURE ]; then",
	    "\techo -n \" capture\"",
	    "\t$RCCAPTURE",
	    "fi");
    };
    Phase "etc", "Creating $PREFIX/etc", sub {
	DoneIfExists("$PREFIX/etc");
	mkdir("$PREFIX/etc",0755) or
	    PhaseFail("Unable to create $PREFIX/etc: $!");
    };
    Phase "rc.capture", "Creating empty $RCCAPTURE", sub {
	DoneIfExists($RCCAPTURE);
	CreateFileFatal($RCCAPTURE,"#!/bin/sh");
	ExecQuietFatal("$CHMOD a+rx $RCCAPTURE");
    };
1062 1063
};

1064
Phase "rc.d", "Setting up rc.d scripts", sub {
1065 1066 1067 1068 1069 1070
    Phase "rsyncd", "Removing rsyncd startup script",  sub {
	DoneIfDoesntExist("$RCDIR/rsyncd.sh");
	if (!unlink "$RCDIR/rsyncd.sh") {
	    PhaseFail("Unable to remove $RCDIR/rsyncd.sh: $!");
	}
    };
1071 1072 1073 1074 1075 1076
    Phase "mysql-server", "Removing $RCDIR/mysql-server.sh", sub {
	DoneIfDoesntExist("$RCDIR/mysql-server.sh");
	if (!unlink "$RCDIR/mysql-server.sh") {
	    PhaseFail("Unable to remove $RCDIR/mysql-server.sh: $!");
	}
    };
1077 1078 1079 1080 1081 1082
    Phase "my-server2", "Removing $RCDIR/mysql-server", sub {
	DoneIfDoesntExist("$RCDIR/mysql-server");
	if (!unlink "$RCDIR/mysql-server") {
	    PhaseFail("Unable to remove $RCDIR/mysql-server: $!");
	}
    };
1083 1084
    if ($ELVIN_COMPAT) {
	Phase "elvin-gateway", "Installing elvin gateway startup file", sub {
1085 1086
	    PhaseSkip("elvind not installed, elvin_gateway not enabled")
		if (! -x "/usr/local/libexec/elvind");
1087 1088 1089 1090
	    DoneIfExists("$RCDIR/3.elvin_gateway.sh");
	    PhaseFail("Pubsub system or elvin_gateway is not installed")
	};
    }
1091
    
1092
    Phase "rc.testbed", "Installing testbed RC scripts", sub {
1093 1094 1095 1096
        Phase "elvind.sh", "Removing port version of elvind.sh", sub {
	    DoneIfDoesntExist("$RCDIR/elvind.sh");
            ExecQuietFatal("/bin/rm -f $RCDIR/elvind.sh");
        };