solution-rpm/build_rpm.sh

58 lines
No EOL
1.6 KiB
Bash
Executable file

#!/bin/bash
# This is a simple script to build an RPM package from a spec file.
# We need to install the required dependencies to build RPM packages.
# We also need to set up the RPM build tree:
#
# $ sudo dnf install rpm-build rpmdevtools dnf-plugins-core
# $ rpmdev-setuptree
#
# To install the builddeps:
#
# $ sudo dnf builddep SolutionTM.spec
version=0.1.0
name=SolutionTM
rpmbuild=$PWD/rpmbuild
mkdir -p $rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
echo "Building RPM package for $name version $version."
# Check so that all versions are coherent
grep -q "Version:.*$version" $name.spec
if [ $? -eq 0 ]; then
echo "Version number in spec file is $version."
else
echo "Version number in spec file is not $version. Exiting."
exit 1
fi
grep -q "version = \"$version\"" Cargo.toml
if [ $? -eq 0 ]; then
echo "Version number in Cargo.toml is $version."
else
echo "Version number in Cargo.toml is not $version. Exiting."
exit 1
fi
source_tar=$name-$version.tar.gz
vendor_tar=$name-$version-vendor.tar.gz
# First, we need a tarball of the source code in this very repo.
git archive --format=tar.gz --prefix=$name-$version/ -o SolutionTM-$version.tar.gz HEAD
# If we want an unclean build, comment out the above line and use the following instead.
# git ls-files | tar --transform='s,^,$name-$version/,' -T - -czf $source_tar
# Then we need a vendor tarball of the dependencies.
cargo vendor --versioned-dirs vendor
tar -cvzf $vendor_tar vendor
# Then we move the tarball to the SOURCES directory.
mv $source_tar $rpmbuild/SOURCES/
mv $vendor_tar $rpmbuild/SOURCES/
rpmbuild --define "_topdir $rpmbuild" -ba $name.spec