From cbb5a644da34bb98087db0d33ce30ac53742341e Mon Sep 17 00:00:00 2001 From: daniceexi Date: Tue, 17 May 2011 07:36:24 +0000 Subject: [PATCH] add a script for building the ipmitool rpm packages for different distors Former-commit-id: 4f213758a3ab243b8d498c6a755b9148fc023037 --- ipmitool/bldipmi.pl | 126 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100755 ipmitool/bldipmi.pl diff --git a/ipmitool/bldipmi.pl b/ipmitool/bldipmi.pl new file mode 100755 index 0000000..f1202ac --- /dev/null +++ b/ipmitool/bldipmi.pl @@ -0,0 +1,126 @@ +#! /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"; +} elsif (grep /SUSE Linux Enterprise Server 10/, @output) { + $os = "sles10"; +} elsif (grep /SUSE Linux Enterprise Server 11/, @output) { + $os = "sles11"; +} 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`; +chomp($pwd); +if ( (! -f "$pwd/ipmitool-1.8.11.tar.gz") + || (! -f "$pwd/ipmitool.spec") + || (! -f "$pwd/ipmitool-saneretry.patch") + || (! -f "$pwd/ipmitool-spdfix.patch") + || (! -f "$pwd/ipmitool-eventfix.patch")) { + print "missed some necessary files for building.\n"; + exit 1; +} + +my $blddir; +if ($os eq "rh5") { + $blddir = "/usr/src/redhat"; +} elsif ($os eq "rh6") { + $blddir = "/root/rpmbuild"; +} elsif ($os =~ /sles1\d/) { + $blddir = "/usr/src/packages"; +} + +#&runcmd("mkdir -p $blddir/SOURCES"); +#&runcmd("mkdir -p $blddir/SPECS"); +#&runcmd("mkdir -p $blddir/BUILD"); +#&runcmd("mkdir -p $blddir/RPMS"); + +# 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 +$cmd = "cp -rf ./ipmitool-1.8.11.tar.gz $blddir/SOURCES/"; +&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 +my $binfile = "$blddir/BUILD/ipmitool-1.8.11/src/ipmitool"; +$cmd = "ldd $binfile"; +@output = `$cmd`; +if (! grep /libcrypto.so/, @output) { + print "The ssl was not enabled.\n"; + exit 1; +} + +my $objrpm = "$blddir/RPMS/$arch/ipmitool-xcat-1.8.11-3.$arch.rpm"; +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"; + } +}