build rpm
All checks were successful
build-rpm / rpm (push) Successful in 11s

This commit is contained in:
Danilo Reyes
2026-02-19 10:37:36 -06:00
parent f7b65d0b8f
commit 0b65727f85
4 changed files with 122 additions and 0 deletions

37
scripts/build-rpm.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -euo pipefail
if ROOT_DIR=$(git -C "${PWD}" rev-parse --show-toplevel 2>/dev/null); then
ROOT_DIR="$ROOT_DIR"
else
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
fi
SPEC_FILE="$ROOT_DIR/packaging/prem2resolve.spec"
if ! command -v rpmspec >/dev/null 2>&1; then
echo "rpmspec not found. Install rpm-build." >&2
exit 1
fi
VERSION=$(rpmspec -q --qf '%{version}\n' "$SPEC_FILE" | head -n1)
NAME=$(rpmspec -q --qf '%{name}\n' "$SPEC_FILE" | head -n1)
DIST_DIR="$ROOT_DIR/dist"
TOPDIR="$ROOT_DIR/rpmbuild"
TARBALL="$DIST_DIR/${NAME}-${VERSION}.tar.gz"
mkdir -p "$DIST_DIR" "$TOPDIR/BUILD" "$TOPDIR/RPMS" "$TOPDIR/SOURCES" "$TOPDIR/SPECS" "$TOPDIR/SRPMS"
if ! git -C "$ROOT_DIR" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "Not a git repository; cannot create source archive." >&2
exit 1
fi
git -C "$ROOT_DIR" archive --format=tar --prefix="${NAME}-${VERSION}/" HEAD | gzip -n > "$TARBALL"
cp "$SPEC_FILE" "$TOPDIR/SPECS/"
cp "$TARBALL" "$TOPDIR/SOURCES/"
rpmbuild --define "_topdir $TOPDIR" -ba "$TOPDIR/SPECS/$(basename "$SPEC_FILE")"
echo "Built RPM(s) in: $TOPDIR/RPMS"