dbfillcheck.in 1.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl -w

#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# 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
my $master_fill   = "$testbed_srcdir/sql/database-fill.sql";
my $export_tables = "../utils/export_tables";
26
my $wap		  = "$testbed_srcdir/utils/withadminprivs";
27
28
29
30
31
my $tempfile      = "/tmp/dbdiff.$$";
my $exitcode      = 0;

#
# Diff exits with 2 if a problem. We tell diff to ignore whitespace
32
33
34
# changes and comment lines (line starting with '--').
#
if (system("perl $wap perl $export_tables | ".
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
	   "diff -b -B -I '^--.*\$' $master_fill - > $tempfile") == 2) {
    unlink($tempfile);
    die("*** $0:\n".
	"    diff $export_tables failed!\n");
}

# No differences ...
if (!$?) {
    unlink($tempfile);
    exit(0);
}

#
# Oh well. Cat the diff to stdout and exit with non-zero status.
#
system("cat $tempfile");
unlink($tempfile);
exit(1);