#!/usr/bin/perl -w # # $Id$ # Copyright B. Cornec 2005-2013 # Provided under the GPL v2 # # Backup the hardware configuration on machine supporting it # (Bios configuration, Raid configuration, ...) # use strict; use File::Basename; =pod =head1 NAME mindi-bkphw keeps track of your hardware configuration (BIOS, Raid, Management board, ...) =head1 DESCRIPTION mindi-bkphw keeps track of your hardware configuration by calling the tool provided by IHV (Independant Hardware Vendor) in order to store the configuration of the system BIOS, the RAID controller or the onboard management card if any of those is present. For the moment, this is only working for HP ProLiant servers, as HP provides all these tools in a convenient way to perform these actions. Other manufacturer can provide patches or relevant info in order to be supported as well here. =head1 SYNOPSIS mindi-bkphw /path/to/cache-dir /path/to/conf-dir =head1 ARGUMENTS =over 4 =item B This is the directory where the generated files will be stored. =item B This is the directory where the configuration file describing the tools needed to backup hardware information is stored. Generaly /etc/mindi. It should contain a deplist.d subdirectory, and for now only the ProLiant.conf file is used in it. =back =head1 WEB SITES The main Web site of the project is available at L. Bug reports should be filled using the trac instance of the project at L. =head1 USER MAILING LIST For community exchanges around MondoRescue please use the list L =head1 AUTHORS The MondoRescue team lead by Bruno Cornec L. =head1 COPYRIGHT MondoRescue is distributed under the GPL v2.0 license or later, described in the file C included with the distribution. =cut # Handling Configuration files my $tool = ""; my $ret = 0; my $productname = undef; die "No CACHE_DIR parameter" if ((not defined $ARGV[0]) || (! -d $ARGV[0])); my $locbkpdir = "/bkphw"; my $bkpdir = "$ARGV[0]$locbkpdir"; die "No CONF_DIR parameter" if ((not defined $ARGV[1]) || (! -d $ARGV[1])); my $confdir = "$ARGV[1]"; die "You need dmidecode for Hardware support\n" if (! -x "/usr/sbin/dmidecode"); mkdir $bkpdir,0755 if (! -d $bkpdir) ; open(SYSTEM,"/usr/sbin/dmidecode -s 'system-product-name' 2> /dev/null |") || die "You need /usr/sbin/dmidecode for mindi hardware support"; while () { next if (/^#/); $productname = $_; chomp($productname); } close(SYSTEM); die "INFO: No product name found for Hardware support\n" if (not defined $productname); if ($productname =~ /proliant/i) { print "Detected a $productname. Nice. Continue to support my job :-)\n"; print "Activating ProLiant support for mindi\n"; print "You can install SDR packages to benefit from mindi's enhanced ProLiant support\n"; print "Get them from http://downloads.linux.hp.com/SDR/\n"; open(PROLIANT,"$confdir/deplist.d/ProLiant.conf") || die "Unable to open $confdir/deplist.d/ProLiant.conf"; # generate a list of what need to be put on the backup media open(TOOLS,"> $bkpdir/../tools.files") || die "Unable to open $bkpdir/../tools.files"; # generate a script that will be launched at rstore time to perform the HW setup open(SCRIPT,"> $bkpdir/../mindi-rsthw") || die "Unable to open $bkpdir/../mindi-rsthw"; print SCRIPT << 'EOF'; #!/bin/bash # # Script generated by mindi # # This script will restore potentially your HW configuration # on your system before partioning occurs. # # You may want to reboot after that step if you think that # resetting BIOS parameters to the value restored # may have an impact on your restoration process or if # you want to benefit from any firmware update that could have happened. # EOF while($tool = ) { my $hasfound = 0; next if ($tool =~ /^#/); chomp($tool); # skip non-executable/exising binaries if (! (-x $tool)) { next; } else { print "Found $tool, activating enhanced HP ProLiant support in mindi\n"; print TOOLS "$tool\n"; } if ($tool =~ /\/conrep$/) { my $xmlf = "/opt/hp/hp-scripting-tools/etc/conrep.xml"; # From the package if (-f $xmlf) { $ret = system("$tool -s -x $xmlf -f$bkpdir/conrep.dat"); # From the SSSTK } else { $xmlf = "/usr/share/conrep/conrep.xml"; if (-f $xmlf) { $ret = system("$tool -s -x $xmlf -f$bkpdir/conrep.dat"); } else { next; } } print SCRIPT "$tool -l -f$locbkpdir/conrep.dat\n"; print TOOLS "$xmlf\n"; } if ($tool =~ /\/hp-rcu$/) { $ret = system("$tool -s -f$bkpdir/conrep.dat"); print SCRIPT "$tool -l -f$locbkpdir/conrep.dat\n"; } if ($tool =~ /\/hpacuscripting$/) { $hasfound = 1; my $dir=basename($tool); # Just backup internal info for a DR $ret = system("$tool -c $bkpdir/hpacuscripting.dat -internal"); # We could want to reset it before. print SCRIPT "# $tool -reset -i $locbkpdir/hpacusripting.dat\n"; print SCRIPT "$tool -i $locbkpdir/hpacusripting.dat\n"; } if ($tool =~ /\/hponcfg$/) { $ret = system("$tool -a -w $bkpdir/hponcfg.dat"); print SCRIPT "$tool -f $locbkpdir/hponcfg.dat\n"; } if ($tool =~ /\.scexe$/) { print "Found $tool, that firmware will be applied at restore time on your HP ProLiant\n"; print SCRIPT "./$tool -s\n"; } if ($tool =~ /\/hp-fm/) { print "Found $tool, firmware will be upgraded at restore time on your HP ProLiant\n"; print SCRIPT "./$tool upgrade\n"; } # Kept for compatibility with older version of tools if (($tool =~ /\/hpacucli$/) && ($hasfound == 0)) { my $dir=basename($tool); $ret = system("$tool -c $bkpdir/hpacucli.dat"); print SCRIPT "$tool -i $locbkpdir/hpacucli.dat\n"; } if ($ret != 0) { print "$tool returned an error. Hardware support may not be complete\n"; } } close(PROLIANT); close(TOOLS); close(SCRIPT); } else { print "\nINFO: No Hardware support for $productname.\nNot a big issue, just less features and risks ;-)\n"; print "You may ask your manufacturer to contribute to the mindi project (harmless)\n"; } rmdir $bkpdir if (-d $bkpdir) ;