#!/usr/bin/perl -w
#
# Backup the hardware configuration on machine supporting it
# (Bios configuration, Raid configuration, ...)
#
use strict;
use AppConfig;

# Handling Configuration files
my $mindiconf=YYY
my $file1 = "$mindiconf/mindi.conf.dist";
my $file2 = "$mindiconf/mindi.conf";
my $tool = "";
my $ret = 0;

my $config = AppConfig->new({
                                # Auto Create variables mentioned in Conf file
                                CREATE => 1,
                                DEBUG => 0,
                                GLOBAL => {
                                        # Each conf item has one single parameter
                                        ARGCOUNT => AppConfig::ARGCOUNT_ONE
                                }
                        });
$config->file($file1, $file2);

open(SYSTEM,"dmidecode -s 'system-product-name' |") || die "You need dmidecode for mindi hardware support";
my $productname = <SYSTEM>;
close(SYSTEM);

chomp($productname);
if ($productname =~ /HP /) {
	print "Detected an HP Hardware. Nice. Continue to support my job :-)";
	if ($productname =~ / proliant /i) {
		print "Activating Proliant support for mindi";
		open(PROLIANT,"$mindiconf/deplist.d/proliant.conf") || die "Unable to open $mindiconf/deplist.d/proliant.conf";
		while($tool = <PROLIANT>) {
			next if ($tool =~ /^#/);
			chomp($tool);
			if (! (-e $tool) {
				print "You should install the SmartStart Scripting toolkit tool $tool\nto benefit from mindi's enhanced hardware support\n";
				print "Get it from http://www.hp.com/servers/sstoolkit\n";
			} else {
				print "Found $tool, activating enhanced HP Proliant support in mindi\n";
			}
			if ($tool =~ /conrep/) {
				$ret = system("$tool -s -f".$config->get("mindi_cache_dir")."/conrep.dat");
			}
			if ($tool =~ /cpqacuxe/) {
				$ret = system("$tool -c ".$config->get("mindi_cache_dir")."/cpqacuxe.dat");
			}
			if ($tool =~ /hponcfg/) {
				$ret = system("$tool -w ".$config->get("mindi_cache_dir")."/hponcfg.dat");
			}
			if ($ret != 0) {
				print "$tool returned an error. Hardware support may not be complete\n";
			}
		}
	}
} else {
	print "No Hardware support for $productname\n";
	print "Ask your manufacturer to contribute to the mindi project\n";
}
