Adds warning not to build as root, otherwise the RVM installer will place two files...
[rvm-ruby.git] / rpm / create_rpm_from_here
1 #!/bin/bash
2
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
5
6 if [ $UID == 0 ]; then
7   echo "Please do not build RPM packages as root"
8   exit 1
9 fi
10
11 set -e
12 set -x
13
14 specfile=`find rpm -name \*.spec |head -1`
15 test -z "$specfile" && exit -1
16
17 specfile=`basename $specfile`
18
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}'`
23
24 rm -rf rpmbuild
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)
29
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
34 popd
35
36 rpmbuild --define "_topdir %(pwd)/rpmbuild" -ba rpmbuild/SPECS/$specfile