dbfillcheck.in 1.71 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
27
28
my $tempdifffile  = "/tmp/dbdiff.$$";
my $tempnewfile   = "/tmp/dbdiff.new.$$";
my $tempoldfile   = "/tmp/dbdiff.old.$$";
29
30
31
32
my $exitcode      = 0;

#
# Diff exits with 2 if a problem. We tell diff to ignore whitespace
33
34
# changes and comment lines (line starting with '--').
#
35
36
37
38
39
40
41
42
43
44
# 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");
}
if (system("sort $master_fill > $tempnewfile")) {
    unlink($tempoldfile);
45
    die("*** $0:\n".
46
	"    sort $master_fill failed!\n");
47
}
48
49
50
51
52
53
54
55
56
if (system("diff -b -B -I '^--.*\$' $tempoldfile $tempnewfile > $tempdifffile")
	== 2) {
    unlink($tempdifffile);
    die("*** $0:\n".
	"    diff $tempoldfile $tempnewfile failed!\n");
}

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

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

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