rpm-ostree/import-spec
Colin Walters d8766bd01c https://github.com/coreos/rpm-ostree/releases/tag/v2022.8
Resolves: rhbz#2077062
  Resolves: rhbz#2023325
2022-04-21 10:31:43 -04:00

55 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
KEEP_V_R=
while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
echo "Usage: $0 [--keep-v-r]" >&2
exit 0
;;
--keep-v-r)
KEEP_V_R=1
;;
*)
echo "$0: unrecognized option: $1" >&2
exit 1
;;
esac
shift
done
main() {
local upstream
upstream=$(get_parsed_spec_field URL)
curl --fail-early -Lo rpm-ostree.spec.new "$upstream/raw/main/packaging/rpm-ostree.spec.in"
sed -ne '/%changelog/,$ p' rpm-ostree.spec >> rpm-ostree.spec.new
if [ -n "${KEEP_V_R}" ]; then
local version release
version=$(get_raw_spec_field Version)
release=$(get_raw_spec_field Release)
sed -ie "s/^Version:.*/Version: $version/" rpm-ostree.spec.new
sed -ie "s/^Release:.*/Release: $release/" rpm-ostree.spec.new
fi
if git diff --quiet --exit-code rpm-ostree.spec; then
mv rpm-ostree.spec.new rpm-ostree.spec
echo "Updated rpm-ostree.spec" >&2
else
echo "Refusing to overwrite dirty rpm-ostree.spec" >&2
echo "Updated rpm-ostree.spec.new" >&2
fi
}
get_parsed_spec_field() {
rpmspec -P rpm-ostree.spec | grep "^${1}: " | head -n1 | cut -d ' ' -f 2
}
get_raw_spec_field() {
grep "^${1}: " rpm-ostree.spec | head -n1 | cut -d ' ' -f 2
}
main "$@"