setbuildinfo.in 2.44 KB
Newer Older
1 2
#!/usr/bin/perl -w
#
3
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25 26 27 28 29 30 31 32 33
#
# 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@';
34
my $SRCDIR    = "@top_srcdir@";
35 36

#
37
# We use the bare module instead of the testbed libdb, so that this
38 39 40
# script can run from a first-time installation, before the latter is
# installed.
#
41
use DBI;
42 43 44 45

#
# Build a list of tables to export
#
46 47 48
my $dbh = DBI->connect("DBI:mysql:database=$DBNAME;host=localhost",
		       undef, "none",
		       {'PrintError' => 0});
49 50 51 52 53 54 55 56 57 58 59 60 61 62
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.
#
63 64 65 66
$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");
67

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

#
# Also store the Git hash into the DB so we can inspect it.
#
my $hash = `cd $SRCDIR; tools/git/current_branch_head`;
if ($?) {
78 79 80 81 82 83 84 85
    print STDERR
	"*** $0:\n".
	"    Unable to get commit hash for source tree\n";

    $hash = "";
}
else {
    chomp($hash);
86 87 88
}
$hash = $dbh->quote($hash);

89 90 91 92
$dbh->do("replace into version_info set ".
	 "   name='commithash', value=$hash")
    or die("*** $0:\n".
	   "    Unable to set version_info 'commithash' to $hash\n");
93

94
exit(0);