setbuildinfo.in 1.75 KB
Newer Older
1 2 3
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2011 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
# We use the bare module instead of the testbed libdb, so that this
21 22 23
# script can run from a first-time installation, before the latter is
# installed.
#
24
use DBI;
25 26 27 28

#
# Build a list of tables to export
#
29 30 31
my $dbh = DBI->connect("DBI:mysql:database=$DBNAME;host=localhost",
		       undef, "none",
		       {'PrintError' => 0});
32 33 34 35 36 37 38 39 40 41 42 43 44 45
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.
#
46 47 48 49
$dbh->do("update sitevariables set value=$buildinfo ".
	 "where name='general/version/build'")
    or die("*** $0:\n".
	   "    Unable to set sitevar 'general/version/build' to $buildinfo\n");
50

51 52 53 54
$dbh->do("replace into version_info set ".
	 "   name='buildinfo', value=$buildinfo")
    or die("*** $0:\n".
	   "    Unable to set version_info 'buildinfo' to $buildinfo\n");
55 56 57 58 59 60

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

    $hash = "";
}
else {
    chomp($hash);
69 70 71
}
$hash = $dbh->quote($hash);

72 73 74 75
$dbh->do("replace into version_info set ".
	 "   name='commithash', value=$hash")
    or die("*** $0:\n".
	   "    Unable to set version_info 'commithash' to $hash\n");
76

77
exit(0);