#!/usr/bin/perl -I/opt/SUNWstade/lib
###########################################################################
# Sun Proprietary/Confidential Code
#
# File:           verifyConfig
# Description:    Given a component name, utility verifies the 
#                 configuration againest factory idefaults.
#
# ident	 "@(#)verifyConfig 1.2	 05/01/25 SMI"
#
# Copyright 2004, Sun Microsystems, Inc. All rights reserved.
###########################################################################

    use File::Basename;
    $PROGNAME = basename ($0, "");
    require "/opt/se6x20/lib/arrayConfigLib";

    &getVars;
    &getArguments;
    $exitCode = 0;

    foreach $name (@ARRAYLIST) {
          print "**********************************\n";
          print "  Checking $name Configuration    \n";
          print "**********************************\n\n";

          $exitCode = 1 if(&openConnection($name));
          $exitCode = 1 if(&checkFruStatus());
          $exitCode = 1 if(&checkSysDefaults());
          $exitCode = 1 if(&checkSetDefaults());
          $exitCode = 1 if(&checkSyslog());
          $exitCode = 1 if(&checkVolExists());
          $exitCode = 1 if(&checkVolStatus());
          $exitCode = 1 if(&checkNtpSetting());
          $exitCode = 1 if(&closeConnection($name));
          
          print "Configuration check on $name is Successful \n\n" if(!$exitCode);
    }
     
    exit $exitCode;

sub getArguments {

    @usage = (
        "usage: $PROGNAME -n <arrayName> [-hv]\n",
        "where: \n",
        "\t-n <ArrayName>        - Array name(s) on which verify configuration to be run\n",
        "\t                      - Array list can be comma separated arraynames OR ALL \n",
	"\t-v                    - verbose mode\n",
        "\t-h                    - print usage\n"
    );

    my($arg);
    my(@list);

    if ($#ARGV<0) {
        print "@usage\n";
        exit 1;
    }

    while ($arg=shift(@ARGV)) 
    {
        if ($arg =~ /-h/i) 
        {
            print @usage;
            exit 1;

        } elsif ($arg =~ /-n/) {
            $arg = shift(@ARGV);
            if ($arg =~/ALL/i) 
            {
                   &getArrayList;
            }
            elsif ($arg =~/array\d+/i) {
                (@tempLIST)=split(/,/,$arg);
                foreach $array (@tempLIST) {
                  $result = `/usr/sbin/ping $array 1 2>&1`;
                  if ($result !~/alive/i)
                    {
                        print ("Warning : $array is offline \n");    
                        exit 1;
                    }
                push(@ARRAYLIST,$array);
               } 
            } else {
                print "Warning : wrong array name, refer to \/etc/\hosts for valid array names.\n";
                exit 1;
            }
        } elsif ($arg =~/-v/i) {
                  $VERBOSE =  TRUE;
        } else { print @usage; exit 1;}
     }
}
