Commit 02cf15cc authored by Leigh Stoller's avatar Leigh Stoller

Add updae wrapper around new Emulab dbupdate script. protogeni/updates

stores the Protogeni specific update stuff. Documentation to follow in
the wiki.
parent 70f98e1f
......@@ -14,7 +14,8 @@ include $(OBJDIR)/Makeconf
SBIN_STUFF = cleanupslice
PSBIN_STUFF = register_resources expire_daemon gencrl postcrl \
createcerts initsite addauthority getcacerts \
gencrlbundle shutdownslice remauthority listusage
gencrlbundle shutdownslice remauthority listusage \
update
# These scripts installed setuid, with sudo.
SETUID_BIN_SCRIPTS =
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2008-2009 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
use English;
use Getopt::Std;
#
# Initialize an emulab to act as a protogeni emulab. Add optional -c
# option if this is a clearinghouse.
#
sub usage()
{
print "Usage: update\n";
exit(1);
}
my $optlist = "";
#
# Configure variables
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
my $PGENIDOMAIN = "@PROTOGENI_DOMAIN@";
my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
my $DBUPDATE = "$TB/sbin/dbupdate";
my $WAP = "$TB/sbin/withadminprivs";
my $SACERT = "$TB/etc/genisa.pem";
my $CMCERT = "$TB/etc/genicm.pem";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
# Protos
sub fatal($);
sub OneShot();
#
# Turn off line buffering on output
#
$| = 1;
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use libtestbed;
use libdb qw(TBSetSiteVar TBSiteVarExists TBGetSiteVar);
use GeniDB;
if ($UID != 0) {
fatal("Must be root to run this script\n");
}
#
# Check args.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
usage()
if (@ARGV);
OneShot();
#
# Apply the dbupdates using the Emulab utility, to all three DBs.
#
system("$DBUPDATE " . GENISA_DBNAME()) == 0
or fatal("Could not apply updates to SA DB");
system("$DBUPDATE " . GENICM_DBNAME()) == 0
or fatal("Could not apply updates to CM DB");
system("$DBUPDATE " . GENICH_DBNAME()) == 0
or fatal("Could not apply updates to CH DB");
exit(0);
#
# A one of a kind update.
#
sub OneShot()
{
if (!TBSiteVarExists("protogeni/sa_uuid") ||
!TBSiteVarExists("protogeni/cm_uuid")) {
fatal("Please update your Emulab sitevars.");
}
if (TBGetSiteVar("protogeni/sa_uuid") eq "") {
#
# Load the SA cert
#
my $certificate = GeniCertificate->LoadFromFile($SACERT);
if (!defined($certificate)) {
fatal("Could not load certificate from $SACERT\n");
}
TBSetSiteVar('protogeni/sa_uuid', $certificate->uuid());
}
if (TBGetSiteVar("protogeni/cm_uuid") eq "") {
#
# Load the CM cert
#
my $certificate = GeniCertificate->LoadFromFile($CMCERT);
if (!defined($certificate)) {
fatal("Could not load certificate from $CMCERT\n");
}
TBSetSiteVar('protogeni/cm_uuid', $certificate->uuid());
}
}
sub fatal($)
{
my ($msg) = @_;
die("*** $0:\n".
" $msg\n");
}
#
# This is the first DB update script. It adds a new table to the DB
# to track version info for doing this.
#
use strict;
use GeniDB;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
DBSetDefault($dbhandle);
if (!DBTableExists("version_info")) {
DBQueryFatal("CREATE TABLE `version_info` ( ".
" `name` varchar(32) NOT NULL default '', ".
" `value` tinytext NOT NULL, ".
" PRIMARY KEY (`name`) ".
") ENGINE=MyISAM DEFAULT CHARSET=latin1");
}
# Initialize new table.
my $query_result =
DBQueryFatal("select value from version_info where name='dbrev'");
if (! $query_result->numrows) {
DBQueryFatal("replace into `version_info` values ('dbrev', '0')");
}
return 0;
}
1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment