ops-install.in 20.1 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
# All rights reserved.
#

#
10
# install-ops - 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@",
Robert Ricci's avatar
Robert Ricci committed
26
27
    "@TBTESTSUITEEMAIL@");

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 $ELABINELAB  = @ELABINELAB@;
38
my $WINSUPPORT  = @WINSUPPORT@;
39

40
41
42
# True if we are also the FS node
my $ISFS	= ($USERNODE eq $FSNODE) ? 1 : 0;

43
44
45
46
# For /share export below.
my $CONTROL_NETWORK = "@CONTROL_NETWORK@";
my $CONTROL_NETMASK = "@CONTROL_NETMASK@";

47
48
49
# Should be configure variable
my $TBADMINGID  = 101;

50
#
Robert Ricci's avatar
Robert Ricci committed
51
# Allow this to work if the library is left in the source directory
52
#
Robert Ricci's avatar
Robert Ricci committed
53
54
55
56
use lib '@srcdir@';
   
use English;
use libinstall;
57
58
59
60
61
62
use Getopt::Std;

#
# Handle command-line options
#
sub usage {
63
    print "Usage: ops-install [-b] [-p packagedir] [-P portname]\n";
64
65
66
    exit(1);
}

67
68
69
70
#
# The default meta-port (name and version) that drags in all the dependancies
# for an ops node
#
71
my $OPS_PORT = "emulab-ops-1.4";
72
my $FS_PORT = "emulab-fs-1.4";
73

74
my $packagedir = "";
75
my $batchmode  = 0;
76
my %opts;
77
if (! getopts("P:p:b", \%opts)) {
78
79
80
81
    usage();
}
if (defined($opts{p})) {
    $packagedir = $opts{p};
82
}
83
if (defined($opts{b})) {
84
85
    $batchmode = 1;
}
86
87
88
if (defined($opts{P})) {
    $OPS_PORT = $opts{P};
}
89
90
91
92

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

94
95
96
97
98
99
100
101
#
# 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/..";

102
#
Robert Ricci's avatar
Robert Ricci committed
103
# Some programs we use
104
#
Robert Ricci's avatar
Robert Ricci committed
105
106
107
my $CHGRP      = "/usr/bin/chgrp";
my $CHMOD      = "/bin/chmod";
my $PW         = "/usr/sbin/pw";
108
my $PATCH      = "/usr/bin/patch";
Robert Ricci's avatar
Robert Ricci committed
109
my $NEWALIASES = "/usr/bin/newaliases";
110
111
my $SH         = "/bin/sh";
my $PKG_INFO   = "/usr/sbin/pkg_info";
112
my $PKG_ADD    = "/usr/sbin/pkg_add";
113
my $PWD        = "/bin/pwd";
114
my $CP         = "/bin/cp";
115
my $MV         = "/bin/mv";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
116
my $GMAKE      = "/usr/local/bin/gmake";
117
my $ENV        = "/usr/bin/env";
118
my $MOUNT      = "/sbin/mount";
119
120

#
Robert Ricci's avatar
Robert Ricci committed
121
# Some files we edit/create
122
#
Robert Ricci's avatar
Robert Ricci committed
123
my $RCCONF          = "/etc/rc.conf";
124
my $HOSTS           = "/etc/hosts";
125
my $FSTAB           = "/etc/fstab";
Robert Ricci's avatar
Robert Ricci committed
126
127
my $RCLOCAL         = "/etc/rc.local";
my $RCCAPTURE       = "$PREFIX/etc/rc.capture";
Robert Ricci's avatar
Robert Ricci committed
128
129
130
131
132
133
134
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";
135
my $SSHD_CONFIG     = "/etc/ssh/sshd_config";
136
my $CRONTAB         = "/etc/crontab";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
137
my $AUTHKEYS	    = "/root/.ssh/authorized_keys";
Kirk Webb's avatar
   
Kirk Webb committed
138
139
my $SMBCONF_FILE    = "/usr/local/etc/smb.conf";
my $SMBCONF_HEAD    = "$SMBCONF_FILE.head";
140
141

#
Robert Ricci's avatar
Robert Ricci committed
142
# Some directories we care about
143
#
144
145
146
147
148
149
150
my $LIST_DIR      = "/etc/mail/lists";
my $TIPLOG_DIR    = "/var/log/tiplogs";
my $PORTSDIR      = "/usr/ports";
my $PORTSMISCDIR  = "$PORTSDIR/misc";
my $SRCDIR        = '@srcdir@';
my $TOP_SRCDIR    = "@top_srcdir@";
my $RCDIR         = "/usr/local/etc/rc.d";
151
my $VARRUN        = "/var/run";
152
153

#
Robert Ricci's avatar
Robert Ricci committed
154
# And some lists that we use
155
#
156
157
my @LOCAL_HOSTS        = ($OURDOMAIN,$BOSSNODE,$USERNODE,$FSNODE);
my @LOGFILES           = ("/var/log/logins","/var/log/tiplogs/capture.log",
Robert Ricci's avatar
Robert Ricci committed
158
    "/var/log/mountd.log");
159
160
my @LOCAL_MAILING_LISTS = grep(/$OURDOMAIN$/,@MAILING_LISTS);
my @MAILING_LIST_NAMES  = map { /^([\w-]+)\@/ } @LOCAL_MAILING_LISTS;
Robert Ricci's avatar
Robert Ricci committed
161
162
163

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

165
166
my @MOUNTPOINTS        = ("/users", "/proj", "/groups", "/share");

167
168
169
170
171
#
# 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";
172
my $M2CRYPTO_PATCH  = "$TOP_SRCDIR/patches/m2crypto.patch";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
173
my $IDENTPUB        = "$TOP_SRCDIR/install/identity.pub";
174

175
176
177
178
#
# List of names that goes into $HOSTS and which must resolve.
# 
my @OPS_NAMES = ($USERNODE, "users", "ops");
179
180
181
if ($ISFS) {
    push(@OPS_NAMES, "fs");
}
182

183
#
Robert Ricci's avatar
Robert Ricci committed
184
# Make sure they know what they're getting into...
185
#
186
187
188
189
if (! $batchmode) {
    print STDERR
	"WARNING: This script is ONLY intended to be run on a machine\n";
    print STDERR
190
	"that is being set up as a dedicated ops or ops+fs node. Continue? [y/N] ";
191
192
193
    my $response = <>;
    die "Installation aborted!\n" unless ($response =~ /^y/i);
}
194

Robert Ricci's avatar
Robert Ricci committed
195
196
if ($UID != 0) {
    die "This script must be run as root.\n";
197
198
199
}

#
Robert Ricci's avatar
Robert Ricci committed
200
# The phases are fairly self-explanatory
201
202
#

Robert Ricci's avatar
Robert Ricci committed
203
204
205
Phase "groups", "Creating admin group", sub {
    if (getgrnam("tbadmin")) {
	PhaseSkip("tbadmin group already exists");
206
    }
207
    ExecQuietFatal("$PW groupadd tbadmin -g $TBADMINGID");
Robert Ricci's avatar
Robert Ricci committed
208
209
210
};

Phase "dirs", "Setting directory permissions", sub {
Robert Ricci's avatar
Robert Ricci committed
211
212
    foreach my $dirref (@TESTBED_DIRS) {
	my ($dir, $newmode) = @$dirref;
Robert Ricci's avatar
Robert Ricci committed
213
214
215
216
	Phase $dir, $dir, sub {
	    if (!-d $dir) {
		PhaseFail("Directory $dir does not exist");
	    }
Robert Ricci's avatar
Robert Ricci committed
217
218
219
220
	    # 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
221
222
	    # Fix up the mode (strip file type)
	    $mode = $mode & 0777;
Robert Ricci's avatar
Robert Ricci committed
223
	    if ($mode == eval $newmode && $group eq getgrnam("tbadmin")) {
Robert Ricci's avatar
Robert Ricci committed
224
225
		PhaseSkip("Already done");
	    }
Robert Ricci's avatar
Robert Ricci committed
226
227
	    ExecQuietFatal("$CHGRP tbadmin $realdir");
	    ExecQuietFatal("$CHMOD $newmode $realdir");
Robert Ricci's avatar
Robert Ricci committed
228
	};
229
    }
Robert Ricci's avatar
Robert Ricci committed
230
};
231

232
Phase "ports", "Installing ports", sub {
233
234
235
236
237
238
239
240
241
    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");
    };
242
243
244
245
246
247
248
249
250
251
252
253
    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");
    };
254
    Phase "pcopy", "Copying ports into place", sub {
255
256
257
	if ($packagedir) {
	    PhaseSkip("Package directory provided");
	}
258
	DoneIfExists("$PORTSMISCDIR/emulab-ops");
259
260
	ExecQuietFatal("$SH $SRCDIR/ports/ports-install");
    };
261
262
    my $pwd = `$PWD`;
    chomp $pwd;
263
    Phase "pinstall", "Installing ports (may take a while)", sub {
264
	if (!ExecQuiet("$PKG_INFO -e $OPS_PORT")) {
265
266
	    PhaseSkip("Ports already installed");
	}
267
268
269
	if ($packagedir) {
	    PhaseSkip("Package directory provided");
	}
270
271
272
273

	#
	# This port is dead-simple, so it's safe to do it from this script
	#
274
275
	chdir "$PORTSMISCDIR/emulab-ops" or
		PhaseFail "Unable to change to $PORTSMISCDIR/emulab-ops: $!";
276
	ExecQuietFatal("make -DBATCH install");
277
    };
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
    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");
	}
	if ($packagedir) {
	    PhaseSkip("Package directory provided");
	}
	    
	chdir "$PORTSMISCDIR/emulab-fs" or
	    PhaseFail "Unable to change to $PORTSMISCDIR/emulab-fs: $!";
	ExecQuietFatal("make -DBATCH install");
    };
    chdir $pwd;
294
295
};

296
297
# XXX Temporary.
Phase "portfixup", "Fixing up packages", sub {
298
    Phase "rsync", "Looking for rsync and installing", sub {
299
300
301
302
	if (!ExecQuiet("$PKG_INFO -x rsync")) {
	    PhaseSkip("rsync already installed");
	}

303
	PhaseFail("Must have PKG_PATH environment variable set")
304
305
306
	    if (!exists($ENV{"PKG_PATH"}));
	
	ExecQuietFatal("$PKG_ADD rsync-2.6.3_1");
307
    };
308
309
    if ($WINSUPPORT) {
	Phase "samba", "Looking for Samba and installing", sub {
310
311
312
	    if (!$ISFS) {
		PhaseSkip("Not FS Node");
	    }
313
314
315
	    if (!ExecQuiet("$PKG_INFO -x samba")) {
		PhaseSkip("samba already installed");
	    }
316
	    
317
	    PhaseFail("Must have PKG_PATH environment variable set")
318
		if (!exists($ENV{"PKG_PATH"}));
319
		
320
321
322
323
324
	    ExecQuietFatal("$PKG_ADD samba-3.0.7,1");
	};
	Phase "gcc30", "Looking for GCC 3.0 and installing", sub {
	    if (!ExecQuiet("$PKG_INFO -x gcc30")) {
		PhaseSkip("GCC 3.0 already installed");
325
	    }
326
	    
327
	    PhaseFail("Must have PKG_PATH environment variable set")
328
329
330
		if (!exists($ENV{"PKG_PATH"}));
	
	    ExecQuietFatal("$PKG_ADD gcc30-3.0.4_1");
331
332
	};
    }
333
334
};

335
336
Phase "patches", "Applying patches", sub {
    Phase "m2cryptopatch", "Patching m2crypto", sub {
337
        if (!ExecQuiet("$PATCH -C -f -l -R -p0 -i $M2CRYPTO_PATCH")) {
338
339
            PhaseSkip("$M2CRYPTO_PATCH already applied");
        }
340
        ExecQuietFatal("$PATCH -f -p0 -l -i $M2CRYPTO_PATCH");
341
342
343
    };
}; 

Robert Ricci's avatar
Robert Ricci committed
344
345
346
Phase "rc.conf", "Adding testbed content to rc.conf", sub {
    DoneIfEdited($RCCONF);
    AppendToFileFatal($RCCONF,
Robert Ricci's avatar
Robert Ricci committed
347
348
349
		      qq|sendmail_enable="YES"|,
		      qq|nfs_server_enable="YES"|,
		      qq|nfs_server_flags="-u -t -n 16"|,
350
		      (($ISFS && $WINSUPPORT) ? qq|smbd_enable="YES"| : ()),
Robert Ricci's avatar
Robert Ricci committed
351
		      qq|syslogd_flags=""|);
Robert Ricci's avatar
Robert Ricci committed
352
};
353

354
Phase "hosts", "Adding boss/ops/fs IP addresses to $HOSTS", sub {
355
    DoneIfEdited($HOSTS);
356
357
358
359
360
361
    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);
362
363
};

364
365
366
367
368
369
370
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) {
371
372
	Phase $name, $name, sub {
	    if (gethostbyname($name)) {
373
		PhaseSucceed("$name resolves");
374
375
376
377
378
379
380
	    } else {
		PhaseFail("$name does not resolve");
	    }
	};
    }
};

Robert Ricci's avatar
Robert Ricci committed
381
382
383
384
385
386
387
388
389
390
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: $!");
391
392
	    ExecQuietFatal("$CHGRP mailnull $LIST_DIR");
	    ExecQuietFatal("$CHMOD 750 $LIST_DIR");
Robert Ricci's avatar
Robert Ricci committed
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
	};
	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 {
408
	    PhaseSkip("No new aliases") unless @MAILING_LIST_NAMES;
Robert Ricci's avatar
Robert Ricci committed
409
410
411
412
413
414
415
416
417
418
419
420
	    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
421
422
	# 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
423
	#
424
425
426
427
	my @dirs = ('/var','/usr/testbed');
	if ($ISFS) {
	    @dirs = ('/users','/groups','/proj',@dirs);
	}
Robert Ricci's avatar
Robert Ricci committed
428
429
430
431
432
433
434
435
436
437
438
439
440
441
	@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,
442
443
		join(" ",@{$filesystems{$key}}) .
		    "\t$BOSSNODE -maproot=root";
Robert Ricci's avatar
Robert Ricci committed
444
445
	}

446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
	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*)/);
	    my $realdir = `realpath /share`;
	    chomp($realdir);
	    push(@exports_lines,
		 "$realdir\t$BOSSNODE -maproot=root");
	    push(@exports_lines,
		 "$realdir\t-network ${a}.${b}.${c} -mask $CONTROL_NETMASK ".
		 "-maproot=root -ro");
	}
461

Robert Ricci's avatar
Robert Ricci committed
462
463
464
465
466
467
468
	#
	# Put them in exports.head, and copy that to /etc/exports
	#
	CreateFileFatal($EXPORTS_HEAD, @exports_lines);
	ExecQuietFatal("cp $EXPORTS_HEAD $EXPORTS_FILE");
    };

469
    # XXX Newhup
Robert Ricci's avatar
Robert Ricci committed
470
471
472
473
474
475
    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");
    };
};
476

477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
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);
	AppendToFileFatal($FSTAB,
		"$FSNODE:/users\t\t/users\tnfs\trw,nodev,nosuid\t0\t0",
		"$FSNODE:/proj\t\t/proj\tnfs\trw,nodev,nosuid\t0\t0",
		"$FSNODE:/groups\t\t/groups\tnfs\trw,nodev,nosuid\t0\t0",
		"$FSNODE:/share\t\t/share\tnfs\trw,nodev,nosuid\t0\t0");
    };
    Phase "mounts", "Mounting NFS filesystems", sub {
	foreach my $dir (@MOUNTPOINTS) {
	    Phase $dir, $dir, sub {
		DoneIfMounted($dir);
		ExecQuietFatal("$MOUNT -o '-R 1' $dir");
	    };
	}
    };
};

509
510
511
#
# Set up syslog
#
Robert Ricci's avatar
Robert Ricci committed
512
513
514
515
516
517
518
519
520
521
522
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>;
523
524
525
	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
526
527
	if (scalar(grep(/^cron/, @sc)) != 1) {
	    PhaseFail("Unable to find marker in /etc/syslog.conf!");
528
529
	}

Robert Ricci's avatar
Robert Ricci committed
530
531
532
533
534
	#
	# Clobber and re-write
	#
	seek(SC,0,0);
	truncate(SC,0);
535

Robert Ricci's avatar
Robert Ricci committed
536
	foreach my $line (@sc) {
537
538
539
540
541
542
543
	    #
	    # 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/;
	    }
544
545
546
547
548
549
550
551
552
553
554
555

	    #
	    # 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
556
	    print SC $line;
557
558
559
560

	    #
	    # Find the cron line, after which we place our auth.info line
	    #
Robert Ricci's avatar
Robert Ricci committed
561
562
563
564
565
566
	    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";
	    }
	}
567

Robert Ricci's avatar
Robert Ricci committed
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
	#
	# 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);
590
		ExecQuietFatal("$CHGRP tbadmin $logfile");
Robert Ricci's avatar
Robert Ricci committed
591
592
593
594
595
596
597
598
599
600
601
602
603
604
		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");
    };
};

605
Phase "cron", "Adding cron jobs", sub {
606
607
608
    if (!$ISFS) {
	PhaseSkip("Not FS node");
    }
609
610
611
    Phase "crontab", "Editing $CRONTAB", sub {
	DoneIfEdited($CRONTAB);
	AppendToFileFatal($CRONTAB,
612
	    "0 \t6\t*\t*\t*\troot\t$PREFIX/sbin/quotamail");
613
614
615
616
617
618
619
    };
    Phase "cronhup", "HUPing cron", sub {
	if (PhaseWasSkipped("crontab")) { PhaseSkip("No new crontab"); }
	HUPDaemon("cron");
    };
};

620
Phase "sudoers", "Editing $SUDOERS to allow wheel group", sub {
Robert Ricci's avatar
Robert Ricci committed
621
622
623
    DoneIfEdited($SUDOERS);
    AppendToFileFatal($SUDOERS,"%wheel    ALL=(ALL) NOPASSWD: ALL");
};
624

625
626
627
628
629
630
631
632
633
634
635
636
637
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");
638
    };
639
640
641
642
643
644
645
646
647
648
649
650
    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 {
	    DoneIfExists("$VARRUN/smbd.pid");
	    ExecQuietFatal("$RCDIR/samba.sh start");
	};
    }
};
651

Robert Ricci's avatar
Robert Ricci committed
652
Phase "ssh", "Allowing root ssh", sub {
Robert Ricci's avatar
Robert Ricci committed
653
654
655
656
657
658
659
660
661
    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: $!");
    };
662
663
664
665
666
667
668
669
670
671
672
673
    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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
};

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");
    };
699
700
};

701
702
Phase "event", "Setting up event system", sub {
    Phase "elvinconf", "Installing elvind config file", sub {
703
	DoneIfIdentical($ELVIND_CONF,$OPS_ELVIND_CONF);
704
705
706
707
	ExecQuietFatal("$CP $OPS_ELVIND_CONF $ELVIND_CONF");
    };
};

708
Phase "rc.d", "Setting up rc.d scripts", sub {
709
710
711
712
713
714
    Phase "rsyncd", "Removing rsyncd startup script",  sub {
	DoneIfDoesntExist("$RCDIR/rsyncd.sh");
	if (!unlink "$RCDIR/rsyncd.sh") {
	    PhaseFail("Unable to remove $RCDIR/rsyncd.sh: $!");
	}
    };
715
    Phase "rc.testbed", "Installing testbed RC scripts", sub {
716
717
718
719
        Phase "elvind.sh", "Removing port version of elvind.sh", sub {
	    DoneIfDoesntExist("$RCDIR/elvind.sh");
            ExecQuietFatal("/bin/rm -f $RCDIR/elvind.sh");
        };
720
721
722
723
724
	DoneIfExists("$RCDIR/2.elvind.sh");
	ExecQuietFatal("$GMAKE -C $TOP_OBJDIR/rc.d control-install");
    };
};

725
726
727
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
728
if (!PhaseWasSkipped("maillists")) {
729
    print "Local mailing lists have been created, with no members, in\n";
Robert Ricci's avatar
Robert Ricci committed
730
    print "$LIST_DIR . Please add members to the following lists:\n";
731
    print map "$_\n", @LOCAL_MAILING_LISTS;
732
}