diff --git a/README.md b/README.md index 319a8ce..540cf1d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # demus-packaging-utils -Aliases and scripts to assist in rpm packaging workflows +Aliases, scripts and rpm macros to assist in rpm packaging workflows + +* regenerate-from-spec: Regenerate tool-generated sources referred to in a spec file +* go-vendor-update: An alias that replicates the parameters used by go2rpm to generate the vendor archive and configuration. It is used in the above regenerate script. +* verify_source_checksum rpm macro: Validate that the checksums in a sources file included in a spec matches the unpacked files. diff --git a/demus-packaging-utils.spec b/demus-packaging-utils.spec new file mode 100644 index 0000000..94a2bff --- /dev/null +++ b/demus-packaging-utils.spec @@ -0,0 +1,48 @@ +Name: demus-packaging-utils +Version: 0.1.0 +Release: %autorelease +Summary: Aliases and scripts to assist in rpm packaging workflows + +License: GPL3 +Source: go-vendor-update.sh +Source: regenerate-from-spec.sh +Source: macros.demus-packaging +Source: LICENSE +Source: README.md + +Requires: bash go-vendor-tools + +BuildArch: noarch + +%description +* Alias to regenerate vendor archive in a go2rpm spec generated with the vendor profile + +%global regen_basename %(basename "%{S:1}" .sh) + +%prep +%if %{exists:%{S:2}} + %{load:%{S:2}} + %verify_source_checksum +%endif + +%build + +%install +%{__install} -m 0755 -d %{buildroot}%{_sysconfdir}/profile.d +%{__install} -m 0755 -d %{buildroot}%{_bindir} +%{__install} -m 0755 -d %{buildroot}%{_rpmmacrodir} + +%{__install} -p -m 644 -t %{buildroot}%{_sysconfdir}/profile.d %{S:0} +%{__install} -p -m 755 %{S:1} %{buildroot}%{_bindir}/%regen_basename +%{__install} -p -m 755 %{S:2} %{buildroot}%{_rpmmacrodir}/ +%{__install} -p -m 644 %{S:3} %{S:4} %{_builddir} + +%files +%doc README.md +%license LICENSE +%{_sysconfdir}/profile.d/* +%{_bindir}/%regen_basename +%{_rpmmacrodir}/* + +%changelog +%autochangelog diff --git a/go-vendor-update.sh b/go-vendor-update.sh new file mode 100644 index 0000000..405359f --- /dev/null +++ b/go-vendor-update.sh @@ -0,0 +1,2 @@ +# Update go vendor archive and config emulating the way go2rpm does it +alias go-vendor-update='go_vendor_archive create --config go-vendor-tools.toml --write-config ' diff --git a/macros.demus-packaging b/macros.demus-packaging new file mode 100644 index 0000000..228627f --- /dev/null +++ b/macros.demus-packaging @@ -0,0 +1,11 @@ +# Verify that the checksums listed in the given file match the checksums of the files in the current directory. +# If the checksum doesn't match an message is printed and the subshell is exited with a non-zero status, +# in order to fail the build. +# The macro should be the first statement in the %prep section. +# +# Control variables, flags and arguments: +# -s path to the file containing the list of checksums. If not provided, the default value is 'sources' +%verify_source_checksum(s:) %{expand: + %define checksumresult %{expand:%(cksum --check --quiet "%{-s:%{-s*}}%{!-s:sources}" 2>/dev/null)} + %[ %{len:%checksumresult} > 0 ? "echo -e 'ERROR: Checksums do not match\\n%{checksumresult}'; exit 1" : "%{nil}" ] +} diff --git a/regenerate-from-spec.sh b/regenerate-from-spec.sh new file mode 100644 index 0000000..f970205 --- /dev/null +++ b/regenerate-from-spec.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Update various generated artifacts in rpm packages +# * Go vendor archive and config +# * COPR source file + +shopt -s extglob + +if [ $# -ne 1 ] || ! [[ "$1" =~ .*.\.spec$ ]]; then + echo "Please provide one .spec file" + echo "Usage: regenerate-from-spec .spec" + exit 1 +fi + +if grep -q go-vendor-tools.toml "$1"; then + echo Updating go vendor archive + go-vendor-update "$1" +fi + +# Update the sources checksums +# We assume all files are lowercase except README and LICENSE files +echo Calculating checksums +cksum -a sha512 {[a-z],README*,LICENSE*}!(ources) > sources +echo Done diff --git a/sources b/sources new file mode 100644 index 0000000..2f44eab --- /dev/null +++ b/sources @@ -0,0 +1,5 @@ +SHA512 (go-vendor-update.sh) = 4ba1a21e84d91d37e66a7ade8eea09bb278ac87d8ea731420c0f56064424cbcc43e1d1f3d80b727472c6a6adeaefb22c909e949b7009c0f6e6bb7c3ace9268dc +SHA512 (macros.demus-packaging) = d0ebab10d2dace6b0a70428d49771a191a91ebe6cdc8b00322b23a2284c8d8413df433c7098ec1f5aaacf7376a191b2bc00c74ac5d8e38e4570565894a93cfc4 +SHA512 (regenerate-from-spec.sh) = a420e572ad92c0cdd140f98fae7b7e96f94c383a83b86bdfb69e6b7d968305391f6d20720df584ca3adb624b5e01d9fa2e4e07b754c176a9f4811b3326d49363 +SHA512 (README.md) = 72a6f0085fea6d2b5736c4fa98f31db8fb42462db6fe65d44de7e99405982cc2330e270f6fb042d598d4136bd2a933e226ae85fb99828e07af6ab2b74a5c89f2 +SHA512 (LICENSE) = ccb0f3b838dff6254510f19c2bd6f5c48e38b8c40a5bf93d38482f4fb31015823741d3f160b6836ec99bd8f4e6c5fa9a5c9196ecdd7775b793f3ada50467aabd