dbfillcheck.in 1.96 KB
Newer Older
1
2
3
4
#!/usr/bin/perl -w

#
# EMULAB-COPYRIGHT
5
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# All rights reserved.
#
use strict;

#
# dbfillcheck - Make sure that the initial fill contents on the
# database match the ones in the checked-out source.  Exits with value
# 1 if the two differ, 0 if they do not, and -1 if some error (such as
# the mysql server is not running, or the database does not exist)
# prevents us from telling if they differ or not.
#

#
# Configure variables
#
my $testbed_srcdir = "@top_srcdir@";

# Locals
24
25
my $dbfill        = "sql/database-fill.sql";
my $master_fill   = "$testbed_srcdir/$dbfill";
26
my $export_tables = "../utils/export_tables";
27
28
29
my $tempdifffile  = "/tmp/dbdiff.$$";
my $tempnewfile   = "/tmp/dbdiff.new.$$";
my $tempoldfile   = "/tmp/dbdiff.old.$$";
30
31
32
33
my $exitcode      = 0;

#
# Diff exits with 2 if a problem. We tell diff to ignore whitespace
34
35
# changes and comment lines (line starting with '--').
#
36
37
38
39
40
41
42
43
# We sort(1) the text files so that we don't pick up differences in ordering,
# which could be pretty random.
#
if (system("perl $export_tables | sort > $tempoldfile")) {
    unlink($tempoldfile);
    die("*** $0:\n".
	"    $export_tables failed!\n");
}
44
if (system("grep -E -v '^(LOCK|UNLOCK|DELETE) ' $master_fill | sort > $tempnewfile")) {
45
    unlink($tempoldfile);
46
    die("*** $0:\n".
47
	"    sort $master_fill failed!\n");
48
}
49
50
51
52
53
54
55
56
57
if (system("diff -b -B -I '^--.*\$' $tempoldfile $tempnewfile > $tempdifffile")
	== 2) {
    unlink($tempdifffile);
    die("*** $0:\n".
	"    diff $tempoldfile $tempnewfile failed!\n");
}

unlink($tempoldfile);
unlink($tempnewfile);
58
59
60

# No differences ...
if (!$?) {
61
    unlink($tempdifffile);
62
63
64
65
    exit(0);
}

#
66
67
# Oh well. Explain to the user what they need to do, and exit with non-zero
# status
68
#
69
70
71
72
print "*** Your installed database is out of date with $dbfill\n";
print "    To bring it up to date, run: \n";
print "    mysqldump tbdb > tbdb.backup\n";
print "    mysql tbdb < $dbfill\n";
73
unlink($tempdifffile);
74
exit(1);