bugdbsetup.in 2.69 KB
Newer Older
1 2 3
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2005, 2006, 2010 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
# All rights reserved.
#
use English;
use Getopt::Std;

#
# Initial bugdb setup. Create bugdn accounts for all users and projects.
#
sub usage()
{
    print STDOUT "Usage: bugdbsetup\n";
    exit(-1);
}
my $optlist  = "d";
my $debug    = 0;
my $impotent = 0;

#
# Configure variables
#
my $TB		= "@prefix@";
my $TBOPS       = "@TBOPSEMAIL@";
my $CONTROL     = "@USERNODE@";
my $BOSSNODE	= "@BOSSNODE@";
my $BUGDBSUPPORT= @BUGDBSUPPORT@;
my $SSH         = "$TB/bin/sshtb";
my $BUGDBPROXY  = "$TB/sbin/bugdbproxy";
my $ADDUSER     = "$TB/sbin/addbugdbuser";
my $ADDPROJ     = "$TB/sbin/addbugdbproj";
my $SETGROUPS   = "$TB/sbin/setbugdbgroups";

#
# Untaint the path
# 
$ENV{'PATH'} = "/bin:/usr/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# Turn off line buffering on output
#
$| = 1;

Leigh B. Stoller's avatar
Leigh B. Stoller committed
47 48 49
# Protos
sub fatal($);

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#
# Load the Testbed support stuff. 
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;

#
# If no bugdb support, just exit. 
#
if (! $BUGDBSUPPORT) {
    print "BUGDB support is not enabled. Exit ...\n";
    exit(0);
}

#
# Only testbed admins.
#
if (!TBAdmin($UID)) {
    die("*** $0:\n".
	"    Must be a testbed admin to run this script\n");
}

#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (defined($options{"d"})) {
    $debug = 1;
}
if (@ARGV) {
    usage();
}

#
# First the projects. Only main group, no subgroups!
#
$query_result =
    DBQueryFatal("select pid from projects ".
		 "where approved=1 ".
94 95
#		 " and (pid='testbed' or pid='emulab-ops' or pid='tbres' or ".
#		 "      pid='utahstud')" .
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
		 "");

while (my ($pid) = $query_result->fetchrow_array()) {
    print "Creating bugdb for project $pid\n"
	if ($debug);
    
    if (!$impotent) {
	system("$ADDPROJ $pid") == 0
	    or fatal("Could not add bugdb for $pid");
    }
}

#
# Now the users.
# 
$query_result =
    DBQueryFatal("select distinct g.uid ".
		 "  from group_membership as g ".
114
		 "left join users as u on u.uid_idx=g.uid_idx ".
115
		 "where u.status='active' and g.trust!='none' ".
116 117 118
#		 "  and (g.pid='testbed' or g.pid='emulab-ops' or ".
#		 "       g.pid='tbres' or g.pid='utahstud')" .
		 "");
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

while (my ($uid) = $query_result->fetchrow_array()) {
    print "Adding user $uid to bugdb\n"
	if ($debug);
    
    if (!$impotent) {
	system("$ADDUSER $uid") == 0
	    or fatal("Could not add bugdb account for $uid");

	system("$SETGROUPS $uid") == 0
	    or fatal("Could not set bugdb groups for $uid");
    }
}

exit(0);

sub fatal($)
{
    my($mesg) = $_[0];

    die("*** $0:\n".
	"    $mesg\n");
}