From ab01b57914a39a8f35c3eae54e1e36f9a2a9def3 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Tue, 10 Sep 2019 12:01:03 -0400 Subject: [PATCH] import-spec: script for importing upstream spec The canonical spec file is now upstream since: https://github.com/projectatomic/rpm-ostree/pull/1900 Add a script to make it trivial to import the spec file here and merge the changelog. There's a `--keep-v-r` flag one can use to keep the Version and Release tags of the existing spec file to deal with e.g. git snapshots (though ideally continuous builds will eventually be handled automatically). --- import-spec | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 import-spec diff --git a/import-spec b/import-spec new file mode 100755 index 0000000..53de1f3 --- /dev/null +++ b/import-spec @@ -0,0 +1,54 @@ +#!/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 -Lo rpm-ostree.spec.new "$upstream/raw/master/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 "$@"