From 3962764fd31e81fcaee2131037a8db0083c43424 Mon Sep 17 00:00:00 2001 From: Brian Stinson Date: Mar 06 2021 01:04:17 +0000 Subject: Put in a wrapper called 'centpkg' that: - Calls get_sources.sh if the git checkout is in the SRPM layout - Pulls sources from the CentOS Stream lookaside if the git checkout is in the dist-git layout Signed-off-by: Brian Stinson --- diff --git a/.centpkg-minimal.metadata b/.centpkg-minimal.metadata new file mode 100644 index 0000000..a73fad9 --- /dev/null +++ b/.centpkg-minimal.metadata @@ -0,0 +1 @@ +cf9ce8d900768ed352a6f19a2857e64403643545 SOURCES/centpkg-minimal.tar.gz diff --git a/SOURCES/centpkg b/SOURCES/centpkg new file mode 100755 index 0000000..420ef2d --- /dev/null +++ b/SOURCES/centpkg @@ -0,0 +1,67 @@ +#!/bin/bash +set -x -e + +# Took this from rhpkg-simple internally owned by lsedlar@redhat.com +pkgname=$(basename "$PWD") +# If running in a git checkout, there will be a config file with url to the +# remote. We can extract package namespace and name from it. If the file is +# missing (which it should not really be), let's default to rpms/ namespace. +ns_pkgname="rpms/$pkgname" +if [ -r .git/config ]; then + url=$(grep " *url *= *" .git/config | cut -d= -f2- | tr -d ' ') + namespace=$(basename "$(dirname "$url")") + ns_pkgname="$namespace/$pkgname" +fi + +if [ -d SPECS ]; then + # We are in the SIG/Exploded SRPM layout so call get_sources.sh + exec /usr/bin/get_sources.sh +fi + + +## This part is also from rhpkg-simple + +if [ -s sources ]; then + baseurl=https://sources.stream.rdu2.redhat.com/sources + + # curl arguments: + # -L follow redirects + # -H Pragma: disable caching + # -o filename where to save results + # -R use timestamp from remote server + # -S display error if there is a problem + # --fail do now write HTML page when there is error + # --retry up to 5 retries for transient errors + # --max-time wait for up to 15 seconds on network error + + # Read first word of first line. For old MD5 format it's the 32 character + # hash. Otherwise let's assume the sources have the BSD format where lines + # start with hash type. + hashtype="$(head -n1 sources | cut -d' ' -f1 | tr '[:upper:]' '[:lower:]')" + if [ "${#hashtype}" -ne 32 ]; then + # The format is + # SHA512 (filename) = ABCDEF + # We don't care about the equals sign. We also assume that all hashes + # are of the same type, so we don't have to read it again for each + # line. + while read -r _ filename _ hash || [[ -n "$filename" && -n "$hash" ]]; do + if [ -z "$filename" ] || [ -z "$hash" ]; then + continue + fi + # Remove parenthesis around tarball name + filename=${filename#(} + tarball=${filename%)} + curl -L -H Pragma: -o "./$tarball" -R -S --fail --retry 5 "$baseurl/$ns_pkgname/$tarball/$hashtype/$hash/$tarball" + done < sources + "${hashtype}sum" -c sources + else + # Ok, we're working with MD5. + while read -r md5sum tarball || [[ -n "$md5sum" && -n "$tarball" ]]; do + if [ -z "$md5sum" ] || [ -z "$tarball" ]; then + continue + fi + curl -L -H Pragma: -o "./$tarball" -R -S --fail --retry 5 "$baseurl/$ns_pkgname/$tarball/$md5sum/$tarball" + done < sources + md5sum -c sources + fi +fi diff --git a/SPECS/centpkg-minimal.spec b/SPECS/centpkg-minimal.spec new file mode 100644 index 0000000..5b1ef9c --- /dev/null +++ b/SPECS/centpkg-minimal.spec @@ -0,0 +1,74 @@ +Name: centpkg-minimal +Version: 2.1.0 +Release: 2%{?dist} +Summary: Used by koji to download sources for building CentOS + +License: MIT +URL: https://git.centos.org/centos-git-common +Source0: %{name}.tar.gz +Source1: centpkg + +BuildArch: noarch +BuildRequires: curl +Requires: util-linux +Requires: curl +Requires: git-core + +%description +Used by koji to download sources for building CentOS + +%prep +%setup -c -n centpkg-minimal +cp %{SOURCE1} . + +%build + + +%install +install -d %{buildroot}%{_bindir} +install -pm 755 get_sources.sh %{buildroot}%{_bindir}/get_sources.sh +install -pm 755 centpkg %{buildroot}%{_bindir}/centpkg + + +%files +%{_bindir}/get_sources.sh +%{_bindir}/centpkg + + +%changelog +* Fri Mar 05 2021 bstinson@redhat.com - 2.1.0-2 +- Add a minimal centpkg binary that calls get_sources or pulls from the CentOS + Stream lookaside based on which layout the repo presents + +* Tue Jun 18 2019 brian@bstinson.com - 2.0.0-2 +- Update the git dep to git-core to pull in fewer deps + +* Tue May 07 2019 Brian Stinson - 2.0.0-1 +- Release for GA + +* Tue Apr 30 2019 Brian Stinson - 1.0.0-9 +- rebuilt + +* Mon Apr 15 2019 Brian Stinson - 1.0.0-8 +- rebuilt + +* Mon Apr 15 2019 Brian Stinson - 1.0.0-7 +- rebuilt + +* Mon Apr 15 2019 Brian Stinson - 1.0.0-6 +- rebuilt + +* Mon Apr 15 2019 brian@bstinson.com - 1.0.0-4 +- Update to not require 'which' + +* Mon Apr 15 2019 Brian Stinson - 1.0.0-4 +- rebuilt + +* Mon Apr 15 2019 Brian Stinson - 1.0.0-3 +- Added requires + +* Mon Apr 15 2019 Brian Stinson - 1.0.0-2 +- rebuilt + +* Mon Apr 15 2019 brian@bstinson.com - 1.0.0-1 +- Initial release