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

#
# EMULAB-COPYRIGHT
5
# Copyright (c) 2003, 2004, 2005 University of Utah and the Flux Group.
6 7 8 9 10 11 12 13 14 15
# All rights reserved.
#

#
# install-ops.sh - Script to do the initial install of an ops node
#
# 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@",
Robert Ricci's avatar
Robert Ricci committed
26 27
    "@TBTESTSUITEEMAIL@");

28

29 30 31 32 33 34 35
my $OURDOMAIN   = '@OURDOMAIN@';
my $USERNODE    = '@USERNODE@';
my $FSNODE      = '@FSNODE@';
my $BOSSNODE    = '@BOSSNODE@';
my $BOSSNODE_IP = '@BOSSNODE_IP@';
my $USERNODE_IP = '@USERNODE_IP@';
my $LOGFACIL    = '@TBLOGFACIL@';
36
my $WINSUPPORT  = @WINSUPPORT@;
37

38 39 40 41
# For /share export below.
my $CONTROL_NETWORK = "@CONTROL_NETWORK@";
my $CONTROL_NETMASK = "@CONTROL_NETMASK@";

42
#
Robert Ricci's avatar
Robert Ricci committed
43
# Allow this to work if the library is left in the source directory
44
#
Robert Ricci's avatar
Robert Ricci committed
45 46 47 48
use lib '@srcdir@';
   
use English;
use libinstall;
49 50 51 52 53 54
use Getopt::Std;

#
# Handle command-line options
#
sub usage {
55
    print "Usage: ops-install [-b] [-p packagedir] [-P portname]\n";
56 57 58
    exit(1);
}

59 60 61 62 63 64
#
# The default meta-port (name and version) that drags in all the dependancies
# for an ops node
#
my $OPS_PORT = "emulab-ops-1.5";

65
my $packagedir = "";
66
my $batchmode  = 0;
67
my %opts;
68
if (! getopts("P:p:b", \%opts)) {
69 70 71 72
    usage();
}
if (defined($opts{p})) {
    $packagedir = $opts{p};
73
}
74
if (defined($opts{b})) {
75 76
    $batchmode = 1;
}
77 78 79
if (defined($opts{P})) {
    $OPS_PORT = $opts{P};
}
80 81 82 83

if (@ARGV) {
    usage();
}
84

85 86 87 88 89 90 91 92
#
# 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/..";

93
#
Robert Ricci's avatar
Robert Ricci committed
94
# Some programs we use
95
#
Robert Ricci's avatar
Robert Ricci committed
96 97 98
my $CHGRP      = "/usr/bin/chgrp";
my $CHMOD      = "/bin/chmod";
my $PW         = "/usr/sbin/pw";
99
my $PATCH      = "/usr/bin/patch";
Robert Ricci's avatar
Robert Ricci committed
100
my $NEWALIASES = "/usr/bin/newaliases";
101 102
my $SH         = "/bin/sh";
my $PKG_INFO   = "/usr/sbin/pkg_info";
103
my $PKG_ADD    = "/usr/sbin/pkg_add";
104
my $PWD        = "/bin/pwd";
105
my $CP         = "/bin/cp";
106
my $MV         = "/bin/mv";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
107
my $GMAKE      = "/usr/local/bin/gmake";
108
my $ENV        = "/usr/bin/env";
109 110

#
Robert Ricci's avatar
Robert Ricci committed
111
# Some files we edit/create
112
#
Robert Ricci's avatar
Robert Ricci committed
113
my $RCCONF          = "/etc/rc.conf";
114
my $HOSTS           = "/etc/hosts";
Robert Ricci's avatar
Robert Ricci committed
115 116
my $RCLOCAL         = "/etc/rc.local";
my $RCCAPTURE       = "$PREFIX/etc/rc.capture";
Robert Ricci's avatar
Robert Ricci committed
117 118 119 120 121 122 123
my $LOCAL_HOSTNAMES = "/etc/mail/local-host-names";
my $ALIASES_FILE    = "/etc/mail/aliases";
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";
124
my $SSHD_CONFIG     = "/etc/ssh/sshd_config";
125
my $CRONTAB         = "/etc/crontab";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
126
my $AUTHKEYS	    = "/root/.ssh/authorized_keys";
127
my $SMBCONF         = "/usr/local/etc/smb.conf";
128 129

#
Robert Ricci's avatar
Robert Ricci committed
130
# Some directories we care about
131
#
Robert Ricci's avatar
Robert Ricci committed
132 133
my $LIST_DIR   = "/etc/mail/lists";
my $TIPLOG_DIR = "/var/log/tiplogs";
134
my $PORTSDIR   = "/usr/ports/misc";
135
my $SRCDIR     = '@srcdir@';
136
my $TOP_SRCDIR = "@top_srcdir@";
137
my $RCDIR      = "/usr/local/etc/rc.d";
138 139

#
Robert Ricci's avatar
Robert Ricci committed
140
# And some lists that we use
141
#
142 143
my @LOCAL_HOSTS        = ($OURDOMAIN,$BOSSNODE,$USERNODE,$FSNODE);
my @LOGFILES           = ("/var/log/logins","/var/log/tiplogs/capture.log",
Robert Ricci's avatar
Robert Ricci committed
144
    "/var/log/mountd.log");
145 146
my @LOCAL_MAILING_LISTS = grep(/$OURDOMAIN$/,@MAILING_LISTS);
my @MAILING_LIST_NAMES  = map { /^([\w-]+)\@/ } @LOCAL_MAILING_LISTS;
Robert Ricci's avatar
Robert Ricci committed
147 148 149

my @TESTBED_DIRS       = ([$PREFIX, "0775"], ["/users", "0755"],
    ["/proj", "0755"], ["/groups", "0755"], ["/share", "0775"]);
150

151 152 153 154 155
#
# A few files we have to deal with
#
my $ELVIND_CONF     = "/usr/local/etc/elvind.conf";
my $OPS_ELVIND_CONF = "$TOP_OBJDIR/event/etc/elvind-ops.conf";
156
my $M2CRYPTO_PATCH  = "$TOP_SRCDIR/patches/m2crypto.patch";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
157
my $IDENTPUB        = "$TOP_SRCDIR/install/identity.pub";
158

159 160 161 162 163 164 165
#
# List of names that goes into $HOSTS and which must resolve.
# 
my @OPS_NAMES = ($USERNODE, "users", "ops");
push(@OPS_NAMES, $FSNODE)
    if ($USERNODE ne $FSNODE);

166
#
Robert Ricci's avatar
Robert Ricci committed
167
# Make sure they know what they're getting into...
168
#
169 170 171 172 173 174 175 176
if (! $batchmode) {
    print STDERR
	"WARNING: This script is ONLY intended to be run on a machine\n";
    print STDERR
	"that is being set up as a dedicated ops node. Continue? [y/N] ";
    my $response = <>;
    die "Installation aborted!\n" unless ($response =~ /^y/i);
}
177

Robert Ricci's avatar
Robert Ricci committed
178 179
if ($UID != 0) {
    die "This script must be run as root.\n";
180 181 182
}

#
Robert Ricci's avatar
Robert Ricci committed
183
# The phases are fairly self-explanatory
184 185
#

Robert Ricci's avatar
Robert Ricci committed
186 187 188
Phase "groups", "Creating admin group", sub {
    if (getgrnam("tbadmin")) {
	PhaseSkip("tbadmin group already exists");
189
    }
Robert Ricci's avatar
Robert Ricci committed
190 191 192 193
    ExecQuietFatal("$PW groupadd tbadmin -g 101");
};

Phase "dirs", "Setting directory permissions", sub {
Robert Ricci's avatar
Robert Ricci committed
194 195
    foreach my $dirref (@TESTBED_DIRS) {
	my ($dir, $newmode) = @$dirref;
Robert Ricci's avatar
Robert Ricci committed
196 197 198 199
	Phase $dir, $dir, sub {
	    if (!-d $dir) {
		PhaseFail("Directory $dir does not exist");
	    }
Robert Ricci's avatar
Robert Ricci committed
200 201 202 203
	    # 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
204 205
	    # Fix up the mode (strip file type)
	    $mode = $mode & 0777;
Robert Ricci's avatar
Robert Ricci committed
206
	    if ($mode == eval $newmode && $group eq getgrnam("tbadmin")) {
Robert Ricci's avatar
Robert Ricci committed
207 208
		PhaseSkip("Already done");
	    }
Robert Ricci's avatar
Robert Ricci committed
209 210
	    ExecQuietFatal("$CHGRP tbadmin $realdir");
	    ExecQuietFatal("$CHMOD $newmode $realdir");
Robert Ricci's avatar
Robert Ricci committed
211
	};
212
    }
Robert Ricci's avatar
Robert Ricci committed
213
};
214

215
Phase "ports", "Installing ports", sub {
216 217 218 219 220 221 222 223 224
    Phase "packages", "Installing packages", sub {
	if (!ExecQuiet("$PKG_INFO -e $OPS_PORT")) {
	    PhaseSkip("Ports already installed");
	}
	if (!$packagedir) {
	    PhaseSkip("No package directory provided");
	}
	ExecQuietFatal("$ENV PKG_PATH=$packagedir $PKG_ADD $OPS_PORT");
    };
225
    Phase "pcopy", "Copying ports into place", sub {
226 227 228
	if ($packagedir) {
	    PhaseSkip("Package directory provided");
	}
229 230 231 232
	DoneIfExists("$PORTSDIR/emulab-ops");
	ExecQuietFatal("$SH $SRCDIR/ports/ports-install");
    };
    Phase "pinstall", "Installing ports (may take a while)", sub {
233
	if (!ExecQuiet("$PKG_INFO -e $OPS_PORT")) {
234 235
	    PhaseSkip("Ports already installed");
	}
236 237 238
	if ($packagedir) {
	    PhaseSkip("Package directory provided");
	}
239 240 241 242 243 244 245 246

	#
	# This port is dead-simple, so it's safe to do it from this script
	#
	my $pwd = `$PWD`;
	chomp $pwd;
	chdir "$PORTSDIR/emulab-ops" or
		PhaseFail "Unable to change to $PORTSDIR/emulab-ops: $!";
247
	ExecQuietFatal("make -DBATCH install");
248 249 250 251
	chdir $pwd;
    };
};

252 253
Phase "patches", "Applying patches", sub {
    Phase "m2cryptopatch", "Patching m2crypto", sub {
254
        if (!ExecQuiet("$PATCH -C -f -l -R -p0 -i $M2CRYPTO_PATCH")) {
255 256
            PhaseSkip("$M2CRYPTO_PATCH already applied");
        }
257
        ExecQuietFatal("$PATCH -f -p0 -l -i $M2CRYPTO_PATCH");
258 259 260
    };
}; 

Robert Ricci's avatar
Robert Ricci committed
261 262 263
Phase "rc.conf", "Adding testbed content to rc.conf", sub {
    DoneIfEdited($RCCONF);
    AppendToFileFatal($RCCONF,
Robert Ricci's avatar
Robert Ricci committed
264 265
		      qq|sendmail_enable="YES"|,
		      qq|nfs_server_enable="YES"|,
266
		      ($WINSUPPORT ? qq|enable_smbd="YES"| : ()),
Robert Ricci's avatar
Robert Ricci committed
267 268
		      qq|nfs_server_flags="-u -t -n 16"|,
		      qq|syslogd_flags=""|);
Robert Ricci's avatar
Robert Ricci committed
269
};
270

271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
Phase "hosts", "Adding boss/ops IP addresses to $HOSTS", sub {
    DoneIfEdited($HOSTS);
    AppendToFileFatal($HOSTS,
		      "${BOSSNODE_IP}\t${BOSSNODE} boss",
		      "${USERNODE_IP}\t@OPS_NAMES");
};

Phase "resolve", "Checking to make sure names for boss/ops resolve", sub {
    foreach my $name (@OPS_NAMES, ${BOSSNODE}, "boss") {
	Phase $name, $name, sub {
	    if (gethostbyname($name)) {
		PhaseSkip("$name resolves");
	    } else {
		PhaseFail("$name does not resolve");
	    }
	};
    }
};

Robert Ricci's avatar
Robert Ricci committed
290 291 292 293 294 295 296 297 298 299
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: $!");
300 301
	    ExecQuietFatal("$CHGRP mailnull $LIST_DIR");
	    ExecQuietFatal("$CHMOD 750 $LIST_DIR");
Robert Ricci's avatar
Robert Ricci committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
	};
	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 {
317
	    PhaseSkip("No new aliases") unless @MAILING_LIST_NAMES;
Robert Ricci's avatar
Robert Ricci committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
	    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
	# filesystems
	#
333
	my @dirs = ('/users','/groups','/proj','/share','/var','/usr/testbed');
Robert Ricci's avatar
Robert Ricci committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347
	@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,
Robert Ricci's avatar
Robert Ricci committed
348
		join(" ",@{$filesystems{$key}}) . "\t$BOSSNODE -maproot=root";
Robert Ricci's avatar
Robert Ricci committed
349 350
	}

351 352 353 354 355 356 357 358 359 360 361
	#
	# /share is special. We want to export that to the control network
	# read-only (it is exported to boss r/w, above).
	#
	my ($a,$b,$c,$d) = ($CONTROL_NETWORK =~ /^(\d*)\.(\d*)\.(\d*)\.(\d*)/);
	my $realdir = `realpath /share`;
	chomp($realdir);
	push(@exports_lines,
	     "$realdir\t-network ${a}.${b}.${c} -mask $CONTROL_NETMASK ".
	     "-maproot=root -ro");

Robert Ricci's avatar
Robert Ricci committed
362 363 364 365 366 367 368
	#
	# Put them in exports.head, and copy that to /etc/exports
	#
	CreateFileFatal($EXPORTS_HEAD, @exports_lines);
	ExecQuietFatal("cp $EXPORTS_HEAD $EXPORTS_FILE");
    };

369
    # XXX Newhup
Robert Ricci's avatar
Robert Ricci committed
370 371 372 373 374 375
    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");
    };
};
376 377 378 379

#
# Set up syslog
#
Robert Ricci's avatar
Robert Ricci committed
380 381 382 383 384 385 386 387 388 389 390
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>;
391 392 393
	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
394 395
	if (scalar(grep(/^cron/, @sc)) != 1) {
	    PhaseFail("Unable to find marker in /etc/syslog.conf!");
396 397
	}

Robert Ricci's avatar
Robert Ricci committed
398 399 400 401 402
	#
	# Clobber and re-write
	#
	seek(SC,0,0);
	truncate(SC,0);
403

Robert Ricci's avatar
Robert Ricci committed
404
	foreach my $line (@sc) {
405 406 407 408 409 410 411
	    #
	    # 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/;
	    }
Robert Ricci's avatar
Robert Ricci committed
412
	    print SC $line;
413 414 415 416

	    #
	    # Find the cron line, after which we place our auth.info line
	    #
Robert Ricci's avatar
Robert Ricci committed
417 418 419 420 421 422
	    if ($line =~ /^cron/) {
		print SC "# " . MAGIC_TESTBED_START . "\n";
		print SC "auth.info\t\t\t\t\t/var/log/logins\n";
		print SC "# " . MAGIC_TESTBED_END . "\n";
	    }
	}
423

Robert Ricci's avatar
Robert Ricci committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
	#
	# Put a few more lines at the end
	#
	print SC "# " . MAGIC_TESTBED_START . "\n";
	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";
	print SC "# " . MAGIC_TESTBED_END . "\n";
	close SC;
    };

    Phase "tiplog", "Creating $TIPLOG_DIR", sub {
	DoneIfExists($TIPLOG_DIR);
	mkdir($TIPLOG_DIR,0755) or PhaseFail("Unable to make $TIPLOG_DIR : $!");
    };
    
    Phase "logfiles", "Creating log files", sub {
	foreach my $logfile (@LOGFILES) {
	    Phase $logfile, $logfile, sub {
		DoneIfExists($logfile);
		CreateFileFatal($logfile);
446
		ExecQuietFatal("$CHGRP tbadmin $logfile");
Robert Ricci's avatar
Robert Ricci committed
447 448 449 450 451 452 453 454 455 456 457 458 459 460
		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",
	    "/var/log/tiplogs/capture.log\t\t644  7     *    168   Z");
    };
};

461 462 463 464
Phase "cron", "Adding cron jobs", sub {
    Phase "crontab", "Editing $CRONTAB", sub {
	DoneIfEdited($CRONTAB);
	AppendToFileFatal($CRONTAB,
465
	    "0 \t6\t*\t*\t*\troot\t$PREFIX/sbin/quotamail");
466 467 468 469 470 471 472
    };
    Phase "cronhup", "HUPing cron", sub {
	if (PhaseWasSkipped("crontab")) { PhaseSkip("No new crontab"); }
	HUPDaemon("cron");
    };
};

Robert Ricci's avatar
Robert Ricci committed
473 474 475 476
Phase "sudoers", "Editing $SUDOERS", sub {
    DoneIfEdited($SUDOERS);
    AppendToFileFatal($SUDOERS,"%wheel    ALL=(ALL) NOPASSWD: ALL");
};
477

478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
if ($WINSUPPORT) {
    Phase "samba", "Setting up Samba", sub {
	Phase "smb.conf", "Installing smb.conf", sub {
	    DoneIfEdited($SMBCONF);
	    ExecQuietFatal("$CP -pf $TOP_OBJDIR/install/smb.conf $SMBCONF");
	    AppendToFileFatal($SMBCONF,
			      "# This file created by Emulab Control");
	};
	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");
	};
    };
}

Robert Ricci's avatar
Robert Ricci committed
494
Phase "ssh", "Allowing root ssh", sub {
Robert Ricci's avatar
Robert Ricci committed
495 496 497 498 499 500 501 502 503
    Phase "sshdconfig", "Permitting root login through ssh", sub {
	DoneIfEdited($SSHD_CONFIG);
	AppendToFileFatal($SSHD_CONFIG,"PermitRootLogin yes");
    };
    Phase "dotssh", "Making root's .ssh directory", sub {
	DoneIfExists("/root/.ssh");
	mkdir("/root/.ssh",0700) or
	    PhaseFail("Unable to create /root/.ssh: $!");
    };
Leigh B. Stoller's avatar
Leigh B. Stoller committed
504 505 506 507 508 509 510 511 512
   Phase "authkeys", "Adding stub identity to /root/.ssh/authorized_keys", sub {
       DoneIfEdited($AUTHKEYS);
       my $ident = `cat $IDENTPUB`;
       PhaseFail("Could not read $IDENTPUB")
	   if ($?);
       chomp($ident);
       AppendToFileFatal($AUTHKEYS,
			 "from=\"${BOSSNODE}\" $ident");
   };
Robert Ricci's avatar
Robert Ricci committed
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
};

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");
    };
538 539
};

540 541
Phase "event", "Setting up event system", sub {
    Phase "elvinconf", "Installing elvind config file", sub {
542
	DoneIfIdentical($ELVIND_CONF,$OPS_ELVIND_CONF);
543 544 545 546
	ExecQuietFatal("$CP $OPS_ELVIND_CONF $ELVIND_CONF");
    };
};

547
Phase "rc.d", "Setting up rc.d scripts", sub {
548 549 550 551 552 553
    Phase "rsyncd", "Removing rsyncd startup script",  sub {
	DoneIfDoesntExist("$RCDIR/rsyncd.sh");
	if (!unlink "$RCDIR/rsyncd.sh") {
	    PhaseFail("Unable to remove $RCDIR/rsyncd.sh: $!");
	}
    };
554
    Phase "rc.testbed", "Installing testbed RC scripts", sub {
555 556 557 558
        Phase "elvind.sh", "Removing port version of elvind.sh", sub {
	    DoneIfDoesntExist("$RCDIR/elvind.sh");
            ExecQuietFatal("/bin/rm -f $RCDIR/elvind.sh");
        };
559 560 561 562 563
	DoneIfExists("$RCDIR/2.elvind.sh");
	ExecQuietFatal("$GMAKE -C $TOP_OBJDIR/rc.d control-install");
    };
};

564 565 566
print "----------------------------------------------------------------------\n";
print "Installation completed succesfully!\n";
print "Please reboot this machine before proceeding with boss setup\n";
Robert Ricci's avatar
Robert Ricci committed
567
if (!PhaseWasSkipped("maillists")) {
568
    print "Local mailing lists have been created, with no members, in\n";
Robert Ricci's avatar
Robert Ricci committed
569
    print "$LIST_DIR . Please add members to the following lists:\n";
570
    print map "$_\n", @LOCAL_MAILING_LISTS;
571
}