libinstall.pm.in 17.9 KB
Newer Older
1 2 3
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2003-2010 University of Utah and the Flux Group.
5 6 7
# All rights reserved.
#
#
8 9
# A simple library for use in the installation scripts, to make them
# seem a little more legitimate, instead of the quick hacks they are.
10
#
Leigh Stoller's avatar
Leigh Stoller committed
11
use POSIX qw(strftime);
12
use Exporter;
13
use vars qw(@EXPORT $TOP_OBJDIR $TOP_SRCDIR
14
	    $TBROOT $LOGDIR $MAINSITE $PGENISUPPORT $GMAKE $PKG_INFO
15
	    $PORTSDIR $VARRUN $RCDIR $MYSQL $DBNAME
16
	    $PROJROOT $PROTOUSER $WAP
17 18
	    $SQL_UPDATE_MAJOR_REVISION $INSTALL_UPDATE_MAJOR_REVISION
	    $HAVE_XERCES);
19

20
@EXPORT = qw($TOP_OBJDIR $TOP_SRCDIR
21
	     $TBROOT $LOGDIR $MAINSITE $PGENISUPPORT $GMAKE $PKG_INFO
22
	     $PORTSDIR $VARRUN $RCDIR $MYSQL $DBNAME
23
	     $PROJROOT $PROTOUSER $WAP
24 25
	     $SQL_UPDATE_MAJOR_REVISION $INSTALL_UPDATE_MAJOR_REVISION
	     $HAVE_XERCES);
26 27 28 29

# Configure variables

$TBROOT        = "@prefix@";
30
$TOP_SRCDIR    = "@top_srcdir@";
31 32 33 34 35
$LOGDIR        = "$TBROOT/log";
$MAINSITE      = @TBMAINSITE@;
$PGENISUPPORT  = @PROTOGENI_SUPPORT@;
$GMAKE         = "/usr/local/bin/gmake";
$PKG_INFO      = "/usr/sbin/pkg_info";
36
$WAP           = "$TBROOT/sbin/withadminprivs";
37 38 39
$PORTSDIR      = "/usr/ports";
$VARRUN        = "/var/run";
$RCDIR         = "/usr/local/etc/rc.d";
40 41
$PROJROOT      = "@PROJROOT_DIR@";
$PROTOUSER     = "elabman";
42

43 44
$DBNAME        = "@TBDBNAME@";
$MYSQL         = "/usr/local/bin/mysql";
45
$HAVE_XERCES   = "@HAVE_XERCES@";
46 47 48 49 50 51

# Change these if the major numbers in sql/updates or install/updates
# are changed.
$SQL_UPDATE_MAJOR_REVISION	= 4;
$INSTALL_UPDATE_MAJOR_REVISION	= 5;

52 53 54 55 56
#
# Make sure that output gets printed right away
#
$| = 1;

57
#
58
# Magic string that shows up in files already edited 
59
#
60
my $MAGIC_TESTBED_VERSION = $INSTALL_UPDATE_MAJOR_REVISION + ".0";
61 62
my $MAGIC_TESTBED_START   = "Added by Emulab - Version: ";
my $MAGIC_TESTBED_END     = "End of Emulab added section";
63

64 65
sub MAGIC_TESTBED_START { $MAGIC_TESTBED_START . $MAGIC_TESTBED_VERSION; }
sub MAGIC_TESTBED_END   { $MAGIC_TESTBED_END; }
66

67 68 69 70 71
# When used in update mode, printing is a little different.
my $updatemode = 0;

# Used by update-install to bump the version number.
sub SET_TESTBED_VERSION($)  { $updatemode = $MAGIC_TESTBED_VERSION = $_[0]; }
72

73 74 75 76
# Set by update-install.
my $impotent   = 0;
my $logfp;
sub SET_IMPOTENT_MODE($)	    { $impotent = 1; $logfp = $_[0]; };
77
sub IMPOTENT_MODE()		    { return $impotent; }
78

79 80 81 82 83
#
# Some programs we may call
#
my $FETCH = "/usr/bin/fetch";

84 85 86 87 88 89 90 91
#
# Figure out which directory we live in, so that some stages can do thing
# relative to it.
#
$TOP_OBJDIR = `/usr/bin/dirname $0`;
chomp $TOP_OBJDIR;
$TOP_OBJDIR = "$TOP_OBJDIR/..";

92 93 94 95
# Real path to the source dir.
$TOP_SRCDIR = `realpath $TOP_SRCDIR`;
chomp $TOP_SRCDIR;

96 97 98 99 100 101 102
#
# Let's pretend perl's exception mechanism has a sane name for the function
# that raises an exception
#
sub throw(@) {
    die @_,"\n";
}
103

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
#
# Start a new installation phase
#
sub Phase($$$) {
    my ($name, $descr, $coderef) = @_;

    push @libinstall::phasestack, $name;
    push @libinstall::descrstack, $descr;
    
    #
    # Okay, this will probably earn me my own special circle in Perl Hell. Use
    # dynamic scoping to allow data to be passed inbetween indirectly recursive
    # calls of Phase(). hasSubPhase is used to determine if we were called
    # recursively in the eval(). skipped and nonSkipped let us figure out if
    # all child calls were skipped. But, we have to give this information to
    # our parent _after_ we declare our own. So, we use references. Damn!
    #
 
    $hasSubPhase++;
    my $firstSubPhase = ($hasSubPhase == 1);
    local $hasSubPhase = 0;
    
    my $parentNonSkipped = \$nonSkipped;
    my $parentSkipped = \$skipped;
    local $nonSkipped = 0;
    local $skipped = 0;
    
    local $depth = ($depth? $depth +1 : 1);
    my $isSubPhase = ($depth > 1);

    my $descrstring = "| " x ($depth -1) . $descr;
135
    if ($firstSubPhase) {
136
	print "\n";
137 138
	printf $logfp "\n"
	    if ($impotent);
139 140
    }
    printf "%-50s", $descrstring;
141 142
    printf $logfp "%-50s", $descrstring
	if ($impotent);
143 144 145 146 147 148

    #
    # Clear these, as we don't want to see the outputs of previous phases
    #
    @libinstall::lastExecOutput = ();
    $libinstall::lastCommand = undef;
149
    @libinstall::loglines = ();
150 151 152 153 154 155 156 157 158 159 160 161 162 163

    #
    # Cool! TWO levels of Perl Hell just for me!
    # We pretend we have real exceptions, here. The way this works, we _expect_
    # something to call die(), which is how you throw exceptions in perl. Neat,
    # huh? The three calls below (Phase?*()) are the ones that do this.
    #
    eval { &$coderef(); };

    #
    # Prepare for printing!
    #
    my $message = "";
    my $die = 0;
164
    my $stop = 0;
165
    if ($hasSubPhase) {
166
	print  "| " x ($depth -1) . "+-" . "--" x (24 - $depth) . "> ";
167 168 169 170 171 172 173
    }

    #
    # Check the exception thrown by the eval()
    #
    SWITCH: for ($@) {
	(/^skip$/) && do {
174
	    print "[ Skipped ($libinstall::reason) ]\n";
175 176
	    print $logfp "[ Skipped ($libinstall::reason) ]\n"
		if ($impotent && defined($logfp));
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
	    $$parentSkipped++;
	    $libinstall::phaseResults{$name} = $_;
	    last SWITCH;
	};

	(/^fail$/) && do {
	    print "[ Failed    ]\n";
	    $$parentNonSkipped++;
	    $libinstall::phaseResults{$name} = $_;
	    $die = 1;
	    $message = "Installation failed: $libinstall::reason";
	    if ($isSubPhase) {
		#
		# Propagate failure up the tree
		#
		PhaseFail($libinstall::reason);
	    }
	    last SWITCH;
	};

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
	(/^stop$/) && do {
	    print "[ Stopped    ]\n";
	    print $logfp "[ Stopped ($libinstall::reason) ]\n"
		if ($impotent && defined($logfp));
	    $$parentNonSkipped++;
	    $message = "$libinstall::reason";
	    if ($impotent) {
		$libinstall::phaseResults{$name} = "succeed";
	    }
	    else {
		$libinstall::phaseResults{$name} = $_;
		$stop = 1;
		if ($isSubPhase) {
		    #
		    # Propagate failure up the tree
		    #
		    PhaseStop($libinstall::reason);
		}
	    }
	    last SWITCH;
	};

219 220 221 222
	(undef || /^$/ || /^succeed$/) && do {
	    #
	    # If we're a parent, and all sub-phases got skipped, we did too
	    #
Leigh Stoller's avatar
Leigh Stoller committed
223 224
	    my $stamp = POSIX::strftime("%H:%M:%S", localtime());
	    
225
	    if ($hasSubPhase && $skipped && ($nonSkipped == 0)) {
Leigh Stoller's avatar
Leigh Stoller committed
226
		print "[ Skipped   ] ($stamp)\n";
227 228
		print $logfp "[ Skipped   ]\n"
		    if ($impotent && defined($logfp));
229 230 231
		$libinstall::phaseResults{$name} = "skip";
		$$parentSkipped++;
	    } else {
232 233 234 235 236 237 238 239 240 241 242 243 244
		if ($impotent) {
		    if (defined($logfp)) {
			print $logfp "[ $libinstall::reason ]\n";
		    
			print $logfp 
			    "> " . join("\n> ", @libinstall::loglines) . "\n"
			    if (@libinstall::loglines);
		    }
		    print "[ $libinstall::reason ]\n";
		}
		else {
		    print "[ Succeeded ] ($stamp)\n";
		}
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
		$$parentNonSkipped++;
		$libinstall::phaseResults{$name} = "succeed";
	    }
	    last SWITCH;
	};

	#
	# Default case - shouldn't get here, unless something called die with
	# the wrong value
	#
	print "[ ERROR     ]\n";
	$$parentNonSkipped++;
	$message = "Internal error - Bad exception:\n$_";
	$libinstall::phaseResults{$name} = "fail";
        $die = 1;
	if ($isSubPhase) {
	    #
	    # Propagate failure up the tree
	    #
	    PhaseFail($message);
	}
    }

268 269 270 271 272 273 274 275 276 277 278 279
    #
    # If we decided that we need to stop, do that now
    #
    if ($stop) {
	print "\n";
	print "############################################################\n";
	print "Installation stopped in phase $name. The reason is:\n";
	print "$message\n";
	print "############################################################\n";
	exit -1;
    }

280 281 282 283
    #
    # If we decided that we need to die, do that now
    #
    if ($die) {
284
	print "\n##### Installation failed in phase $name. The error was:\n";
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
	print "$message\n";
	PrintPhaseTrace();
	PrintLastOutput();
	print "Please send the above output to testbed-ops\@emulab.net\n";
	exit -1;
    }

    #
    # Pop ourselves off the phase stack!
    #
    pop @libinstall::phasestack;
    pop @libinstall::descrstack;

}

#
# Signal that the current phase has suceeded
#
sub PhaseSucceed(;$) {
    ($libinstall::reason) = (@_);
    if (!$libinstall::reason) {
	$libinstall::reason = "succeeded";
    }
    throw "succeed";
}

#
# Signal that the current phase has failed
#
sub PhaseFail($) {
    ($libinstall::reason) = (@_);
    throw "fail";
}

319 320 321 322 323 324 325 326
#
# Signal that the current phase needs to stop so the user can do something.
#
sub PhaseStop($) {
    ($libinstall::reason) = (@_);
    throw "stop";
}

327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
#
# Signal that the current phase is being skipped
#
sub PhaseSkip($) {
    ($libinstall::reason) = (@_);
    throw "skip";
}

#
# Check to see if a previous phase was skipped. Returns 1 if it was, 0 if not
#
sub PhaseWasSkipped($) {
    my ($phase) = (@_);
    return ($libinstall::phaseResults{$phase} &&
    	($libinstall::phaseResults{$phase} =~ /^skip$/));
}

344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
#
# For impotent mode.
#
sub PhaseWouldHave($) {
    ($libinstall::reason) = (@_);
    throw "succeed";
}

#
# Also for impotent mode; detailed logging.
#
sub PhaseLog(@) {
    (@libinstall::loglines) = (@_);
}

#
# Also for impotent mode; log differences to a file.
#
sub DiffFiles($$) {
    my ($src,$dst) = @_;

    return
	if (!$impotent);

    if (! -e $dst) {
	my $stuff = `cat $src`;
	PhaseLog(split('\n', $stuff));
    }
    my $diff = `diff $src $dst`;
    PhaseLog(split('\n', $diff));
}
    
376 377 378 379 380 381
#
# Check to see if the phase is already done, as evidenced by the existance of
# a file
#
sub DoneIfExists($) {
    my ($filename) = @_;
382
    if (!$filename) { PhaseFail("Bad filename passed to DoneIfExists"); }
383
    if (-e $filename) {
384
	PhaseSkip("File already exists");
385 386 387
    }
}

388 389 390 391 392 393 394
#
# Same as above, but done if it doesn't exist
#
sub DoneIfDoesntExist($) {
    my ($filename) = @_;
    if (!$filename) { PhaseFail("Bad filename passed to DoneIfExists"); }
    if (!-e $filename) {
395
	PhaseSkip("File does not exist");
396 397 398
    }
}

399 400 401 402 403 404
#
# Check to see if the phase is already done, as evidenced by the existance of
# comments within a file
#
sub DoneIfEdited($) {
    my ($filename) = @_;
405
    if (!$filename) { PhaseFail("Bad filename passed to DoneIfEdited"); }
406
    my $magic_string = MAGIC_TESTBED_START();
407
    open(FH,$filename) or return;
408
    if (grep /$magic_string/, <FH>) {
409
        close(FH);
410
	PhaseSkip("File has already been edited");
411
    }
412
    close(FH);
413 414 415 416 417 418
}

#
# Check to see if the phase is already done, as evidenced by the fact that two
# files are identical
#
419
sub DoneIfIdentical($$) {
420 421 422 423
    my ($filename1,$filename2) = @_;
    if (!$filename1 || !$filename2) {
	PhaseFail("Bad filename passed to DoneIfIdentical");
    }
424 425 426
    if (!-e $filename1 || !-e $filename2) {
	return;
    }
427 428
    system("cmp -s $filename1 $filename2");
    if (! $?) {
429
	PhaseSkip("Files $filename1 and $filename2 are identical");
430 431 432
    }
}

433 434 435 436 437
#
# Done if package installed.
#
sub DoneIfPackageInstalled($) {
    my ($pname) = @_;
Mike Hibler's avatar
Mike Hibler committed
438
    my $foo = `$PKG_INFO -x $pname 2>&1`;
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
    if (! $?) {
	PhaseSkip("already installed");
    }
}

#
# Backup a file or fail.
#
sub BackUpFileFatal($)
{
    my ($filename) = @_;
    my $suffix     = time();
    my $backup     = $filename . "-" . $suffix;

    PhaseFail("$filename does not exist")
	if (! -e $filename);
Leigh Stoller's avatar
Leigh Stoller committed
455 456 457 458 459 460 461

    if (-e $backup) {
	sleep(1);
	$backup = $filename . "-" . time();
	PhaseFail("$backup already exists")
	    if (-e $backup);
    }
462 463 464 465 466

    ExecQuietFatal("/bin/cp -p $filename $backup")
	if (!$impotent);
}

467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
#
# Check to see if filesystem already mounted
#
sub DoneIfMounted($)
{
    my ($dir) = @_;

    #
    # Grab the output of the mount command and parse. 
    #
    if (! open(MOUNT, "/sbin/mount|")) {
	PhaseFail("Cannot run mount command");
    }
    while (<MOUNT>) {
	if ($_ =~ /^([-\w\.\/:\(\)]+) on ([-\w\.\/]+) \((.*)\)$/) {
	    # Search for nfs string in the option list.
	    foreach my $opt (split(',', $3)) {
		if ($opt eq "nfs") {
		    if ($dir eq $2) {
			close(MOUNT);
487
			PhaseSkip("NFS dir already mounted");
488 489 490 491 492 493 494 495 496
		    }
		}
	    }
	}
    }
    close(MOUNT);
    return;
}

497 498 499 500 501 502 503 504 505 506
#
# Append some text to a configuration file, with a special testbed tag that 
# will help inform the user of what's been done, and help future invocations
# tell that this has already been done. Returns undef if it succeeds, or
# an error string if it fails
# TODO - handle alternate comment characters
# TODO - handle files that it's OK to create
#
sub AppendToFile($@) {
    my ($filename, @lines) = @_;
507 508 509 510 511 512

    if ($impotent) {
	PhaseLog(@lines);
	PhaseWouldHave("append to $filename");
	return undef;
    }
513 514 515 516 517 518
    if (!-e $filename) {
	return "File $filename does not exist";
    }
    open(FH,">>$filename") or return "Unable to open $filename for ".
	"writing: $!";

519
    print FH "# " . MAGIC_TESTBED_START() . "\n";
520
    print FH map "$_\n", @lines;
521
    print FH "# " . MAGIC_TESTBED_END() . "\n";
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544

    close(FH);

    return undef;
}

#
# Same as above, but call PhaseFail on failure
#
sub AppendToFileFatal($@) {
    my ($filename,@lines) = @_;
    my $error = AppendToFile($filename,@lines);
    if ($error) {
	PhaseFail($error);
    }
}

#
# Create a new file (must not already exist), and fill it with the given
# contents. Returns undef if successful, or an error message otherwise.
#
sub CreateFile($;@) {
    my ($filename,@lines) = @_;
545 546 547 548 549 550

    if ($impotent) {
	PhaseLog(@lines);
	PhaseWouldHave("create $filename");
	return undef;
    }
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 577
    if (-e $filename) {
	return "File $filename already exists";
    }
    open(FH,">$filename") or return "Unable to open $filename for ".
	"writing: $!";

    if (@lines) {
	print FH map "$_\n", @lines;
    }

    close FH;
    return undef;    
}

#
# Same as above, but call PhaseFail on failure
#
sub CreateFileFatal($@) {
    my ($filename,@lines) = @_;
    my $error = CreateFile($filename,@lines);
    if ($error) {
	PhaseFail($error);
    }
}

#
# Execute a program, hiding its stdout and stderr from the user, but saving
578 579 580
# them for later use. Returns the exit value of the program if used in scalar
# context, or an array composed of the exit status and output if used in array
# context.
581 582 583 584 585 586
#
sub ExecQuiet(@) {
    #
    # Use a pipe read, so that we save away the output
    #
    my $commandstr = join(" ",@_);
587 588 589 590 591 592

    if ($impotent) {
	PhaseWouldHave("exec($commandstr)");
        return 0;
    }
    
593 594 595 596 597 598 599 600 601 602 603 604
    my @output = ();
    open(PIPE,"$commandstr 2>&1 |") or return -1;
    while (<PIPE>) {
	push @output, $_;
    }
    close(PIPE);

    my $exit_value  = $? >> 8;

    @libinstall::lastExecOutput = @output;
    $libinstall::lastCommand = $commandstr;

605 606 607 608 609
    if (wantarray) {
	return ($exit_value, @output);
    } else {
	return $exit_value;
    }
610 611 612 613 614 615 616 617
}

#
# Same as the above, but the current phase fails if the program returns a non-0
# exit status.
#
sub ExecQuietFatal(@) {
    if (ExecQuiet(@_)) {
618 619
	my $msg = join(' ', @_);
	PhaseFail("Unable to execute: '$msg'");
620 621 622
    }
}

623
#
624
# Signal a daemon, if it's PID file exists. If we can't kill it, we assume that
625 626 627 628 629
# it's because it wasn't running, and skip the phase. Fails if it has trouble
# reading the pid file.
# Takes the name of the daemon as an argument, and assumes
# that the pid file is /var/run/$name.pid
#
630 631
sub SignalDaemon($$) {
    my ($name,$sig) = @_;
632 633 634 635 636 637 638 639
    my $pidfile = "/var/run/$name.pid";
    PhaseSkip("$name is not running") unless (-e $pidfile);
    open(PID,$pidfile) or PhaseFail("Unable to open pidfile $pidfile");
    my $pid = <PID>;
    chomp $pid;
    close PID;

    PhaseFail("Bad pid ($pid) in $pidfile\n") unless ($pid =~ /^\d+$/);
640 641 642 643 644 645 646

    if ($impotent) {
	PhaseWouldHave("signal($sig) $name");
	return;
    }
    if (!kill($sig, $pid)) {
	PhaseSkip("$name is not running");
647 648 649
    }
}

650 651 652 653 654 655
sub HUPDaemon($) {
    my ($name) = @_;

    SignalDaemon($name, 'HUP');
}

656 657 658
#
# Restart a daemon if running. Do not start if not running.
#
659 660
sub RestartDaemon($;$) {
    my ($name, $path) = @_;
661 662 663 664 665 666 667 668 669 670 671 672 673 674

    my $pidfile = "$VARRUN/${name}.pid";

    if (! -e "$VARRUN/stated.pid") {
	PhaseSkip("Testbed not running");
    }
    if (!-e $pidfile) {
	PhaseSkip("$name not running");
    }
    if ($impotent) {
	PhaseWouldHave("restart $name");
	return 1;
    }
    SignalDaemon($name, 'TERM');
675
    sleep(1);
676 677 678
    $path = "$TBROOT/sbin/$name"
	if (!defined($path));
    if (ExecQuiet($path) == 0) {
679 680 681 682 683
	PhaseSucceed("$name started");
    }
    PhaseFail("Could not start $name");
}

684 685 686 687 688 689
#
# Fetch a file from the network, using any protocol supported by fetch(1).
# Arguments are URL and a local filename. Retunrns 1 if succesful, 0 if not.
#
sub FetchFile($$) {
    my ($URL, $localname) = @_;
690 691 692 693 694 695

    if ($impotent) {
	PhaseLog("$URL --> $filename");
	PhaseWouldHave("fetch $URL");
	return 1;
    }
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
    if (ExecQuiet("$FETCH -o $localname $URL")) {
	return 0;
    } else {
	return 1;
    }
}

#
# Same as above, but failure is fatal
#
sub FetchFileFatal($$) {
    my ($URL, $localname) = @_;
    if (!FetchFile($URL,$localname)) {
	PhaseFail("Unable to fetch $URL");
    }
}

713 714 715 716 717 718 719 720 721 722 723 724
#
# Locate the proper version of a package to install by looking
# at the available package tarballs.
#
# Must be called "in phase" since we will PhashFail on errors.
#
sub GetPackage($$) {
    my ($prefix, $packagedir) = @_;

    PhaseFail("Must provide -p (packagedir) argument!")
	if (!$packagedir);

725
    my $pname = `ls $packagedir/$prefix-*.tbz 2>/dev/null`;
726
    if ($?) {
727
	$pname = `ls $packagedir/$prefix-*.tgz 2>/dev/null`;
728 729 730 731 732 733 734 735
	PhaseFail("Cannot find $prefix package in $packagedir!")
	    if ($?);
    }
    chomp($pname);

    return $pname;
}

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
#
# Print out the phase stack that got us here
#
sub PrintPhaseTrace() {
    print "-------------------------------------------------- Phase Stack\n";
    my @tmpphase = @libinstall::phasestack;
    my @tmpdescr = @libinstall::descrstack;
    my ($phase, $descr);
    while (@tmpdescr) {
	($phase, $descr) = (pop @tmpphase, pop @tmpdescr);
	printf "%-10s %-50s\n", $phase, $descr;
    }
    print "--------------------------------------------------------------\n";
}

#
# Print out the ouput of the last command that ran
#
sub PrintLastOutput() {
    if (!$libinstall::lastCommand) {
	return;
    }
    print "------------------------------------------ Last Command Output\n";
    print "Command: $libinstall::lastCommand\n";
    print @libinstall::lastExecOutput;
    print "--------------------------------------------------------------\n";
}

Leigh Stoller's avatar
Leigh Stoller committed
764 765 766 767 768 769 770 771 772 773
#
# Get me a secret
#
sub GenSecretKey()
{
    my $key=`/bin/dd if=/dev/urandom count=128 bs=1 2> /dev/null | /sbin/md5`;
    chomp($key);
    return $key;
}

774
1;