#!/usr/bin/perl -w # # check.data # # See that the major files are available, as well as # making sure that the fields in defs.wh are all present. # # This is used to insure that a system being updated # has all of the pieces needed. It is not foolproof # at all, but does catch large classes of problems. # # Usage: # SupportBin/check.data master # SupportBin/check.data slave # # It is important that this be started from the top # of the application area from the main Makefile. This # allows us to know a certain amount of information. # # Dave Regan # regan@peak.org # http://cornvalley.peak.org/ # Copyright 1998 Dave Regan, all rights reserved # use vars qw($ApplRoot $CheckDataVersion @Dirs); $CheckDataVersion = 'check.data v1.03 regan@ao.com'; use English; $ApplRoot = "/home/regan/public_html/update" if (!defined($ApplRoot)); require "$ApplRoot/bin/appl.lc"; @Dirs = ( "Config", "Registration", "SupportBin", "Template", "bin", "doc" ); ### ### Main program ### ### Site installation should not have to change anything below here. ### my($rc); $rc = 0; if ($PERL_VERSION < 5.003) { print STDERR "We need perl 5.003 or greater\n"; exit 1; } if (defined($ARGV[0])) { if ($ARGV[0] eq "master") { DoMaster(); } elsif ($ARGV[0] eq "slave") { $rc = DoSlave(); } else { print STDERR "check.data $CheckDataVersion\n"; print STDERR "Usage: check.data master|slave\n"; exit 1; } } else { $rc = DoSlave(); } exit $rc; ### ### DoMaster ### ### Make a record of this system for later comparison. ### Part of this is recording the non-cooked information ### from the defs.wh file, and also all of the files ### in certain key directories. ### sub DoMaster { my($dir, $dir2, $file, $key); open(DATA, ">$ApplRoot/Config/data") || die "Cannot open $ApplRoot/Config/data"; print DATA "# Do not edit this file, it is created by check.data.\n\n"; # Record the information (non-processed) from defs.wh for $key (sort keys(%Head)) { print DATA "#define $key\t$Head{$key}\n"; } # Record the files in a number of key directories for $dir (@Dirs) { $dir2 = "$ApplRoot/$dir"; if (!opendir(DIR, $dir2)) { # print STDERR "Cannot open $dir2\n"; next; } @files = readdir(DIR); closedir(DIR); for $file (@files) { next if (-d "$dir2/$file"); next if ("$dir2/$file" eq "Config/checksums"); next if ($file =~ /\.diff$/ || $file =~ /\.dist$/); next if ($file =~ /testsite$/ || $file =~ /distributionsite$/); next if ($file =~ /test/ || $file =~ /\.old$/); print DATA "#file $dir $file\n"; } } close DATA; } ### ### DoSlave ### ### See that all of the needed components exist. ### sub DoSlave { my($dir, $dir2, $file, $key, $rc); if (!open(DATA, "<$ApplRoot/Config/data")) { print "Cannot open $ApplRoot/Config/data.\n" . "Make sure that the application tar file is generating\n" . "Config/data.\n"; exit 1; } $rc = 0; while () { chomp; if (/#define\s+(\S+)\s+(\S+)/) { $Head2{$1} = $2; } elsif (/#file\s+(\S+)\s+(\S+)/) { if (! -f "$ApplRoot/$1/$2" && $2 !~ /\.dist$/ && $2 !~ /\.diff$/ && $2 ne "checksums") { $rc = 1; print STDERR "Cannot find $1/$2\n"; } } } close DATA; # Check header values for $key (sort keys(%Head2)) { if (!defined($Head{$key})) { $rc = 1; print STDERR "defs.wh is missing $key. ", "It should be something like $Head2{$key}\n"; } } return $rc; }