3 # This script will build a RPM from the files in the current directory, given that there is a rpm/file.spec
4 # Its primary purpose is to be used by Jenkins
7 echo "Please do not build RPM packages as root"
14 specfile=`find rpm -name \*.spec |head -1`
15 test -z "$specfile" && exit -1
17 specfile=`basename $specfile`
19 name=`grep -P '^Name:\s+' rpm/$specfile |awk '{print $2}'`
20 commitdate=`git log -1 --format="%ct"`
21 version=`grep -P '^Version:\s+' rpm/$specfile |awk '{print $2}'`.$commitdate
22 #release=`grep -P '^Release:\s+' rpm/$specfile |awk '{print $2}'`
25 mkdir -p rpmbuild/{BUILD,RPMS,SOURCES/$name-$version,SPECS,SRPMS,tmp}
26 cp -a rpm/$specfile rpmbuild/SPECS
27 sed -i "s/^[\t ]*Version:.*\$/Version: ${version}/" rpmbuild/SPECS/$specfile
28 #tar --exclude-vcs --exclude='rpmbuild' --exclude='rpm' -cp * | (cd rpmbuild/SOURCES/$name-$version ; tar xp)
30 pushd rpmbuild/SOURCES
31 #tar cf $name-$version.tar $name-$version # Best not to use cpu on our small ec2 instances
32 #sed -i "s/^[\t ]*Source0:.*/Source0: $name-$version.tar/g" rpmbuild/SPECS/*.spec
33 #sed -i "s/^[\t ]*%setup[\t ]\+-n[\t ]\+.*/%setup -n $name-$version/g" rpmbuild/SPECS/*.spec
36 rpmbuild --define "_topdir %(pwd)/rpmbuild" -ba rpmbuild/SPECS/$specfile