2016-04-30 09:40:40 +02:00
|
|
|
#!/bin/bash -e
|
2015-09-01 21:32:54 +02:00
|
|
|
|
2017-05-22 10:17:59 +02:00
|
|
|
. /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
|
|
|
|
}
|
|
|
|
|
2015-09-01 21:32:54 +02:00
|
|
|
|
|
|
|
if [ ! -e dist/redhat/build_rpm.sh ]; then
|
|
|
|
echo "run build_rpm.sh in top of scylla-jmx dir"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-10-12 22:39:47 +02:00
|
|
|
|
2017-05-22 10:17:59 +02:00
|
|
|
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
|
2017-07-27 18:00:45 +02:00
|
|
|
TARGET=./dist/redhat/mock/scylla-jmx-epel-7-x86_64.cfg
|
2017-05-22 10:17:59 +02:00
|
|
|
elif [ "$ID" = "fedora" ]; then
|
|
|
|
TARGET=$ID-$VERSION_ID-x86_64
|
|
|
|
else
|
|
|
|
echo "Please specify target"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2015-10-12 22:39:47 +02:00
|
|
|
|
2018-04-08 14:21:38 +02:00
|
|
|
if [[ "$TARGET" = epel-7-x86_64 ]]; then
|
|
|
|
TARGET=./dist/redhat/mock/scylla-jmx-epel-7-x86_64.cfg
|
|
|
|
fi
|
|
|
|
|
2017-05-22 10:17:59 +02:00
|
|
|
if [ ! -f /usr/bin/mock ]; then
|
|
|
|
pkg_install mock
|
|
|
|
fi
|
|
|
|
if [ ! -f /usr/bin/git ]; then
|
|
|
|
pkg_install git
|
2015-09-01 21:32:54 +02:00
|
|
|
fi
|
2018-06-06 20:31:13 +02:00
|
|
|
if [ ! -f /usr/bin/pystache ]; then
|
|
|
|
if is_redhat_variant; then
|
|
|
|
sudo yum install -y python2-pystache || sudo yum install -y pystache
|
|
|
|
elif is_debian_variant; then
|
|
|
|
sudo apt-get install -y python-pystache
|
|
|
|
fi
|
|
|
|
fi
|
2015-10-12 22:39:47 +02:00
|
|
|
|
2015-09-17 09:16:12 +02:00
|
|
|
VERSION=$(./SCYLLA-VERSION-GEN)
|
|
|
|
SCYLLA_VERSION=$(cat build/SCYLLA-VERSION-FILE)
|
|
|
|
SCYLLA_RELEASE=$(cat build/SCYLLA-RELEASE-FILE)
|
2018-03-27 21:17:43 +02:00
|
|
|
git archive --format=tar --prefix=scylla-jmx-$SCYLLA_VERSION/ HEAD -o build/scylla-jmx-$VERSION.tar
|
2018-06-06 20:31:13 +02:00
|
|
|
pystache dist/redhat/scylla-jmx.spec.mustache "{ \"version\": \"$SCYLLA_VERSION\", \"release\": \"$SCYLLA_RELEASE\" }" > build/scylla-jmx.spec
|
2017-05-22 10:17:59 +02:00
|
|
|
|
2018-07-19 18:32:58 +02:00
|
|
|
# mock generates files owned by root, fix this up
|
|
|
|
fix_ownership() {
|
|
|
|
sudo chown "$(id -u):$(id -g)" -R "$@"
|
|
|
|
}
|
|
|
|
|
2018-03-27 21:17:43 +02:00
|
|
|
sudo mock --buildsrpm --root=$TARGET --resultdir=`pwd`/build/srpms --spec=build/scylla-jmx.spec --sources=build/scylla-jmx-$VERSION.tar
|
2018-07-19 18:32:58 +02:00
|
|
|
fix_ownership build/srpms
|
2018-03-27 21:17:43 +02:00
|
|
|
sudo mock --rebuild --root=$TARGET --resultdir=`pwd`/build/rpms build/srpms/scylla-jmx-$VERSION*.src.rpm
|
2018-07-19 18:32:58 +02:00
|
|
|
fix_ownership build/rpms
|