2011-05-17 07:36:24 +00:00
|
|
|
#! /usr/bin/perl
|
|
|
|
|
|
|
|
#check the distro
|
|
|
|
$cmd = "cat /etc/*release";
|
|
|
|
@output = `$cmd`;
|
|
|
|
my $os;
|
|
|
|
if (grep /Red Hat Enterprise Linux Server release 5\.\d/, @output) {
|
|
|
|
$os = "rh5";
|
|
|
|
} elsif (grep /Red Hat Enterprise Linux Server release 6\.\d/, @output) {
|
|
|
|
$os = "rh6";
|
2014-12-18 03:03:43 +00:00
|
|
|
} elsif (grep /Red Hat Enterprise Linux Server release 7\.\d/, @output) {
|
|
|
|
$os = "rh7";
|
2011-05-17 07:36:24 +00:00
|
|
|
} elsif (grep /SUSE Linux Enterprise Server 10/, @output) {
|
|
|
|
$os = "sles10";
|
|
|
|
} elsif (grep /SUSE Linux Enterprise Server 11/, @output) {
|
|
|
|
$os = "sles11";
|
2013-10-24 06:15:20 +00:00
|
|
|
} elsif (grep /SUSE Linux Enterprise Server 12/, @output) {
|
|
|
|
$os = "sles12";
|
2011-05-17 07:36:24 +00:00
|
|
|
} else {
|
|
|
|
print "unknow os\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cmd = "uname -p";
|
|
|
|
my $arch = `$cmd`;
|
|
|
|
chomp($arch);
|
|
|
|
|
|
|
|
print "The build env is: $os-$arch\n";
|
|
|
|
|
|
|
|
# check whether the openssl-devel has been isntalled
|
|
|
|
my $cmd = "rpm -qa | grep openssl";
|
|
|
|
my @output = `$cmd`;
|
|
|
|
if ( ! grep /openssl-devel|libopenssl/, @output ) {
|
|
|
|
print "Please installed openssl-devel/libopenssl first. (openssl-devel for rh5/sles10; libopenssl for sles11)\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# check the source files
|
|
|
|
my $pwd = `pwd`;
|
2015-11-05 10:28:40 +00:00
|
|
|
my $version = "1.8.15";
|
2011-05-17 07:36:24 +00:00
|
|
|
chomp($pwd);
|
2015-11-05 10:28:40 +00:00
|
|
|
if ( (! -f "$pwd/ipmitool-$version.tar.gz")
|
2011-05-17 07:36:24 +00:00
|
|
|
|| (! -f "$pwd/ipmitool.spec")
|
2015-11-05 10:28:40 +00:00
|
|
|
|| (! -f "$pwd/ipmitool-$version-saneretry.patch")
|
|
|
|
|| (! -f "$pwd/ipmitool-$version-rflash.patch")) {
|
2011-05-17 07:36:24 +00:00
|
|
|
print "missed some necessary files for building.\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $blddir;
|
|
|
|
if ($os eq "rh5") {
|
|
|
|
$blddir = "/usr/src/redhat";
|
2014-12-18 03:03:43 +00:00
|
|
|
} elsif (($os eq "rh6") || ($os eq "rh7")) {
|
2011-05-17 07:36:24 +00:00
|
|
|
$blddir = "/root/rpmbuild";
|
|
|
|
} elsif ($os =~ /sles1\d/) {
|
|
|
|
$blddir = "/usr/src/packages";
|
|
|
|
}
|
|
|
|
|
2016-02-19 16:20:01 +00:00
|
|
|
&runcmd("mkdir -p $blddir/SOURCES");
|
|
|
|
&runcmd("mkdir -p $blddir/SPECS");
|
|
|
|
&runcmd("mkdir -p $blddir/BUILD");
|
|
|
|
&runcmd("mkdir -p $blddir/RPMS");
|
2011-05-17 07:36:24 +00:00
|
|
|
|
|
|
|
# clean the env
|
|
|
|
$cmd = "rm -rf $blddir/SOURCES/ipmitool*";
|
|
|
|
&runcmd($cmd);
|
|
|
|
$cmd = "rm -rf $blddir/SPECS/ipmitool*";
|
|
|
|
&runcmd($cmd);
|
|
|
|
$cmd = "rm -rf $blddir/BUILD/ipmitool*";
|
|
|
|
&runcmd($cmd);
|
|
|
|
$cmd = "rm -rf $blddir/RPMS/$arch/ipmitool*";
|
|
|
|
&runcmd($cmd);
|
|
|
|
|
|
|
|
# copy the build files
|
2015-11-05 10:28:40 +00:00
|
|
|
$cmd = "cp -rf ./ipmitool-$version.tar.gz $blddir/SOURCES/";
|
2011-05-17 07:36:24 +00:00
|
|
|
&runcmd($cmd);
|
|
|
|
|
|
|
|
$cmd = "cp -rf ./*.patch $blddir/SOURCES/";
|
|
|
|
&runcmd($cmd);
|
|
|
|
|
|
|
|
$cmd = "cp -rf ./ipmitool.spec $blddir/SPECS/";
|
|
|
|
&runcmd($cmd);
|
|
|
|
|
|
|
|
$cmd = "rpmbuild -bb $blddir/SPECS/ipmitool.spec";
|
|
|
|
&runcmd($cmd);
|
|
|
|
|
|
|
|
#check whether the ssl has been enabled
|
2015-11-05 10:28:40 +00:00
|
|
|
my $binfile = "$blddir/BUILD/ipmitool-$version/src/ipmitool";
|
2011-05-17 07:36:24 +00:00
|
|
|
$cmd = "ldd $binfile";
|
|
|
|
@output = `$cmd`;
|
|
|
|
if (! grep /libcrypto.so/, @output) {
|
|
|
|
print "The ssl was not enabled.\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2016-07-18 07:26:15 +00:00
|
|
|
my $objrpm = "$blddir/RPMS/$arch/ipmitool-xcat-$version-2.$arch.rpm";
|
2011-05-17 07:36:24 +00:00
|
|
|
my $dstdir = "/tmp/build/$os/$arch";
|
|
|
|
|
|
|
|
# check the build result
|
|
|
|
if (! -f $objrpm) {
|
|
|
|
print "The rpm file was not generated successfully\n";
|
|
|
|
exit 1;
|
|
|
|
} else {
|
|
|
|
$cmd = "mkdir -p $dstdir";
|
|
|
|
&runcmd ($cmd);
|
|
|
|
$cmd = "cp -rf $objrpm $dstdir";
|
|
|
|
&runcmd ($cmd);
|
|
|
|
print "The obj file has been built successfully, you can get it here: $dstdir\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub runcmd () {
|
|
|
|
my $cmd = shift;
|
|
|
|
print "++++Trying to run command: [$cmd]\n";
|
|
|
|
my @output = `$cmd`;
|
|
|
|
if ($?) {
|
|
|
|
print "A error happened when running the comamnd [$cmd]\n";
|
|
|
|
print "error message: @output\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
if ($verbose) {
|
|
|
|
print "run cmd message: @output\n";
|
|
|
|
}
|
|
|
|
}
|