firstuser 2.59 KB
Newer Older
1 2 3 4 5 6 7
#
# The template
#
use strict;
use libinstall;
use installvars;

8 9
my $EXTRADSA_KEY = "$main::TOP_SRCDIR/install/elabinelab.pub";

10 11 12 13 14 15 16 17 18 19 20 21 22
sub Install($$$)
{
    my ($server, $isupdate, $impotent) = @_;

    # Replace if this script does an update for ip/domain.
    return 0
	if ($isupdate);

    Phase "firstuser", "Setting up initial user ($PROTOUSER)", sub {
	Phase "firstuser", "Calling 'firstuser' to create account", sub {
	    PhaseSkip("$PROTOUSER already created")
		if (-d "$USERROOT/$PROTOUSER");
	    ExecQuietFatal("perl $TOP_OBJDIR/utils/firstuser -b ".
Leigh B Stoller's avatar
Leigh B Stoller committed
23 24
			   (defined($password) ?
			    " -p " . EscapeShellArg($password) : ""));
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
	};
	Phase "Fixing", "Fixing up DB state for $PROTOUSER", sub {
	    my ($exitval, @rows) =
		ExecQuiet("echo 'select uid from users ".
			  "  where uid=\"$PROTOUSER\" and webonly=0' ".
			  "| $MYSQL -s $DBNAME");
	    if ($exitval) {
		PhaseFail("Error running query");
	    }
	    if (scalar @rows) {
		PhaseSkip("Already done");
	    }
	    ExecQuietFatal("echo 'update users set webonly=0 ".
			   "  where uid=\"$PROTOUSER\"' | $MYSQL -s $DBNAME");
	};
	Phase "Thawing", "Thawing $PROTOUSER", sub {
	    my ($exitval, @rows) =
		ExecQuiet("echo 'select uid from users ".
			  "  where uid=\"$PROTOUSER\" and status=\"active\"' ".
			  "| $MYSQL -s $DBNAME");
	    if ($exitval) {
		PhaseFail("Error running query");
	    }
	    if (scalar @rows) {
		PhaseSkip("Already done");
	    }
	    ExecQuietFatal("echo 'update users set status=\"active\" ".
			   "  where uid=\"$PROTOUSER\"' | $MYSQL -s $DBNAME");
	    ExecQuietFatal("$SUDO -u $PROTOUSER $WAP $TBACCT -b thaw $PROTOUSER");
	};
Leigh B Stoller's avatar
Leigh B Stoller committed
55 56 57 58 59

	#
	# Note that account/tbacct has a special case for the protouser;
	# the initial unencrypted keys are not created, so this check works.
	#
60 61 62 63 64 65 66 67 68 69 70 71 72
	Phase "DSAKey", "Adding DSA key to $PROTOUSER account", sub {
	    my ($exitval, @rows) =
		ExecQuiet("echo 'select * from user_pubkeys ".
			  " where uid=\"$PROTOUSER\"' | $MYSQL -s $DBNAME");
	    if ($exitval) {
		PhaseFail("Error running query");
	    }
	    if (scalar @rows) {
		PhaseSkip("Already done");
	    }
	    ExecQuietFatal("$SUDO -u $PROTOUSER $WAP ".
			   "  $ADDPUBKEY -f -u $PROTOUSER $PROTOUSER_KEY");
	};
73 74 75 76 77 78 79
	Phase "DSAKey2", "Adding Extra DSA key to $PROTOUSER account", sub {
	    PhaseSkip("No key found")
		if (! -e $EXTRADSA_KEY);

	    ExecQuietFatal("$SUDO -u $PROTOUSER $WAP ".
			   "  $ADDPUBKEY -R -f -u $PROTOUSER $EXTRADSA_KEY");
	};
80 81 82 83 84 85 86 87 88 89 90
	Phase "authkeys", "Generating authorized_keys for $PROTOUSER", sub {
	    ExecQuietFatal("$SUDO -u $PROTOUSER $WAP $ADDPUBKEY -w $PROTOUSER");
	};
    };

    return 0;
}

# Local Variables:
# mode:perl
# End: