#!/usr/bin/perl
#
# Copyright (C) 2003 VA Linux Systems Japan, K.K.
#
# LICENSE NOTICE
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program 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 General Public License for more details.

# $Id: checkstatus,v 1.2 2004/04/02 02:34:09 taru Exp $

use Getopt::Std;

getopt('f');
($status) = @ARGV;

if (!open(CONF, "<$opt_f")) {
    print "Can't open $opt_f\n";
    exit(2);
}

if (!open(STATUS, "<$status")) {
    print "Can't open $opt_f\n";
    exit(2);
}

$nrpl = 0;

while (<CONF>) {
    /^replica/ && $nrpl++;
}

$nl = 0;

while (<STATUS>) {
    if (!/^\S+:\d+:\d+:\d+\n$/) {
	print "status file is wrong\n";
	exit(1);
    }
    $nl++;
}

if ( $nrpl == $nl ) {
    print "status file is right\n";
    exit(0);
} else {
    print "status file is wrong\n";
    exit(1);
}
