setbuildinfo.in 1.83 KB
Newer Older
1 2 3
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16
# All rights reserved.
#
# Set the version and build info into the DB, at a toplevel install.
#
use English;
use Getopt::Std;
use POSIX qw(strftime);

#
# Configure variables
#
my $DBNAME    = '@TBDBNAME@';
17
my $SRCDIR    = "@top_srcdir@";
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 47 48 49 50 51

#
# We use the bare Mysql module instead of the testbed libdb, so that this
# script can run from a first-time installation, before the latter is
# installed.
#
use Mysql;

#
# Build a list of tables to export
#
my $dbh = Mysql->connect('localhost', $DBNAME, undef, undef);
if (!$dbh) {
    die("*** $0:\n".
	"    Unable to connect to mysqld\n");
}

#
# Easy, get the build version which is simply today's date. 
#
my $buildinfo = POSIX::strftime("%m/%d/20%y", localtime());
$buildinfo = $dbh->quote($buildinfo);

#
# And store into the appropriate sitevar.
#
my $query_result =
    $dbh->query("update sitevariables set value=$buildinfo ".
		"where name='general/version/build'");
if (!$query_result) {
    die("*** $0:\n".
	"    Unable to set sitevar 'general/version/build' to $buildinfo\n");
}

52 53 54 55 56 57 58 59 60 61 62 63 64
$query_result =
    $dbh->query("replace into version_info set ".
		"   name='buildinfo', value=$buildinfo");
if (!$query_result) {
    die("*** $0:\n".
	"    Unable to set version_info 'buildinfo' to $buildinfo\n");
}

#
# Also store the Git hash into the DB so we can inspect it.
#
my $hash = `cd $SRCDIR; tools/git/current_branch_head`;
if ($?) {
65 66 67 68 69 70 71 72
    print STDERR
	"*** $0:\n".
	"    Unable to get commit hash for source tree\n";

    $hash = "";
}
else {
    chomp($hash);
73 74 75 76 77 78 79 80 81 82 83
}
$hash = $dbh->quote($hash);

$query_result =
    $dbh->query("replace into version_info set ".
		"   name='commithash', value=$hash");
if (!$query_result) {
    die("*** $0:\n".
	"    Unable to set version_info 'commithash' to $hash\n");
}

84
exit(0);