dist/redhat: Use mock for CentOS/RHEL rpms

Enable mock for CentOS/RHEL, also support cross building by mock.

See scylladb/scylla#630

Signed-off-by: Takuya ASADA <syuu@scylladb.com>
Message-Id: <20170522081759.8574-1-syuu@scylladb.com>
This commit is contained in:
Takuya ASADA 2017-05-22 17:17:59 +09:00 committed by Pekka Enberg
parent 8176d5729f
commit fa72ea29d3

View File

@ -1,34 +1,71 @@
#!/bin/bash -e #!/bin/bash -e
RPMBUILD=`pwd`/build/rpmbuild . /etc/os-release
print_usage() {
echo "build_rpm.sh -target epel-7-x86_64 --configure-user"
echo " --target target distribution in mock cfg name"
exit 1
}
TARGET=
while [ $# -gt 0 ]; do
case "$1" in
"--target")
TARGET=$2
shift 2
;;
*)
print_usage
;;
esac
done
is_redhat_variant() {
[ -f /etc/redhat-release ]
}
pkg_install() {
if is_redhat_variant; then
sudo yum install -y $1
else
echo "Requires to install following command: $1"
exit 1
fi
}
if [ ! -e dist/redhat/build_rpm.sh ]; then if [ ! -e dist/redhat/build_rpm.sh ]; then
echo "run build_rpm.sh in top of scylla-jmx dir" echo "run build_rpm.sh in top of scylla-jmx dir"
exit 1 exit 1
fi fi
sudo yum install -y rpm-build git if [ "$(arch)" != "x86_64" ]; then
echo "Unsupported architecture: $(arch)"
exit 1
fi
if [ -z "$TARGET" ]; then
if [ "$ID" = "centos" -o "$ID" = "rhel" ] && [ "$VERSION_ID" = "7" ]; then
TARGET=epel-7-x86_64
elif [ "$ID" = "fedora" ]; then
TARGET=$ID-$VERSION_ID-x86_64
else
echo "Please specify target"
exit 1
fi
fi
OS=`awk '{print $1}' /etc/redhat-release` if [ ! -f /usr/bin/mock ]; then
if [ "$OS" = "Fedora" ] && [ ! -f /usr/bin/mock ]; then pkg_install mock
sudo yum -y install mock fi
elif [ "$OS" = "CentOS" ] && [ ! -f /usr/bin/yum-builddep ]; then if [ ! -f /usr/bin/git ]; then
sudo yum -y install yum-utils pkg_install git
fi fi
VERSION=$(./SCYLLA-VERSION-GEN) VERSION=$(./SCYLLA-VERSION-GEN)
SCYLLA_VERSION=$(cat build/SCYLLA-VERSION-FILE) SCYLLA_VERSION=$(cat build/SCYLLA-VERSION-FILE)
SCYLLA_RELEASE=$(cat build/SCYLLA-RELEASE-FILE) SCYLLA_RELEASE=$(cat build/SCYLLA-RELEASE-FILE)
mkdir -p $RPMBUILD/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} git archive --format=tar --prefix=scylla-jmx-$SCYLLA_VERSION/ HEAD -o build/scylla-jmx-$VERSION.tar
git archive --format=tar --prefix=scylla-jmx-$SCYLLA_VERSION/ HEAD -o build/rpmbuild/SOURCES/scylla-jmx-$VERSION.tar cp dist/redhat/scylla-jmx.spec.in build/scylla-jmx.spec
cp dist/redhat/scylla-jmx.spec.in $RPMBUILD/SPECS/scylla-jmx.spec sed -i -e "s/@@VERSION@@/$SCYLLA_VERSION/g" build/scylla-jmx.spec
sed -i -e "s/@@VERSION@@/$SCYLLA_VERSION/g" $RPMBUILD/SPECS/scylla-jmx.spec sed -i -e "s/@@RELEASE@@/$SCYLLA_RELEASE/g" build/scylla-jmx.spec
sed -i -e "s/@@RELEASE@@/$SCYLLA_RELEASE/g" $RPMBUILD/SPECS/scylla-jmx.spec
if [ "$OS" = "Fedora" ]; then sudo mock --buildsrpm --root=$TARGET --resultdir=`pwd`/build/srpms --spec=build/scylla-jmx.spec --sources=build/scylla-jmx-$VERSION.tar
rpmbuild -bs --define "_topdir $RPMBUILD" $RPMBUILD/SPECS/scylla-jmx.spec sudo mock --rebuild --root=$TARGET --resultdir=`pwd`/build/rpms build/srpms/scylla-jmx-$VERSION*.src.rpm
/usr/bin/mock rebuild --resultdir=`pwd`/build/rpms $RPMBUILD/SRPMS/scylla-jmx-$VERSION*.src.rpm
else
sudo yum-builddep -y $RPMBUILD/SPECS/scylla-jmx.spec
rpmbuild -ba --define "_topdir $RPMBUILD" $RPMBUILD/SPECS/scylla-jmx.spec
fi