#!/bin/bash warn() { echo "$1" >&2 } die() { warn "fatal: $1" exit 3 } usage() { warn "usage: $0 [options] COPR_PROJECT" warn "" warn "Options:" warn "" warn " -b BRN build from branch BRN (default: last tag)" warn " -n dry mode, don't do anything (just show" warn " what would be done)" warn " -r REL use REL as Release number in SPEC file" warn " -v VER use VER as Version number in SPEC file" warn " -u URL use URL as base (to get last tag and" warn " compose Source0 in SPEC file)" warn "" warn "If -b is not used, build is launched from last tag available" warn "in the GitHub repo. In that case, Release is '1' and Version" warn "is deduced from the tag by removing the initial 'v'." warn "" warn "If -b is used, the project repo is temporarily clonded, and" warn "both Version and Release are found by consulting git-describe" warn "on the specified branch." exit 2 } last_version() { git ls-remote --tag "$UrlBase" \ | grep '/tags/' \ | cut -d/ -f3 \ | sort -V \ | tail -1 \ | sed "s/^v//" } mkspec() { local self_version self_version="slop-build-copr $(git describe --tags)" sed -e " /^Version/ s|__SLOP_VERSION__|$Version| /^Release/ s|__SLOP_RELEASE__|$Release| /^Source0/ s|__SLOP_URLBASE__|$UrlBase| /^# spec file/ s|__SLOP_BUILDSCRIPT_VERSION__|$self_version| " /dev/null \ || die "copr not found, try 'sudo install python-copr'" if test -n "$Branch"; then die "not implemented" test -n "$Version" || Version=$(git_guess ver) test -n "$Release" || Release=$(git_guess rel) else test -n "$Version" || Version=$(last_version) test -n "$Release" || Release=1 fi mkspec >"$Tmp/slop.spec" $DryRun && { warn "dry mode active, we would build:" warn " at $CoprProject" test -n "$Branch" && warn " using branch $Branch" test -n "$Branch" || warn " using last tag" warn " from $UrlBase" warn " yielding slop-$Version-$Release.*.rpm" warn "" warn "===== BEGIN slop.spec =====" cat "$Tmp/slop.spec" warn "===== END slop.spec =====" exit 1 } copr build --nowait "$CoprProject" "$Tmp/slop.spec" rm -rf "$Tmp" } main "$@"