#!/bin/bash # This script will build a RPM from the files in the current directory, given that there is a rpm/file.spec # Its primary purpose is to be used by Jenkins set -e set -x specfile=`find rpm -name \*.spec |head -1` test -z "$specfile" && exit -1 specfile=`basename $specfile` name=`grep -P '^Name:\s+' rpm/$specfile |awk '{print $2}'` commitdate=`git log -1 --format="%ct"` version=`grep -P '^Version:\s+' rpm/$specfile |awk '{print $2}'`.$commitdate #release=`grep -P '^Release:\s+' rpm/$specfile |awk '{print $2}'` rm -rf rpmbuild mkdir -p rpmbuild/{BUILD,RPMS,SOURCES/$name-$version,SPECS,SRPMS,tmp} cp -a rpm/$specfile rpmbuild/SPECS sed -i "s/^[\t ]*Version:.*\$/Version: ${version}/" rpmbuild/SPECS/$specfile #tar --exclude-vcs --exclude='rpmbuild' --exclude='rpm' -cp * | (cd rpmbuild/SOURCES/$name-$version ; tar xp) pushd rpmbuild/SOURCES #tar cf $name-$version.tar $name-$version # Best not to use cpu on our small ec2 instances #sed -i "s/^[\t ]*Source0:.*/Source0: $name-$version.tar/g" rpmbuild/SPECS/*.spec #sed -i "s/^[\t ]*%setup[\t ]\+-n[\t ]\+.*/%setup -n $name-$version/g" rpmbuild/SPECS/*.spec popd rpmbuild --define "_topdir %(pwd)/rpmbuild" -ba rpmbuild/SPECS/$specfile