Blob Blame History Raw
From 46742b119b95230093b9b3b894aab8ba2210c038 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= <lsedlar@redhat.com>
Date: Thu, 8 Dec 2016 14:56:37 +0100
Subject: [PATCH 1/4] Read BSD formatted sources
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch adds logic to test format of the file and then constructs the
URL appropriately. The command to verify downloaded files is updated to
check the actually used hash.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
---
 AUTHORS.md |  1 +
 bin/fedpkg | 28 +++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/AUTHORS.md b/AUTHORS.md
index c1658b1..654b506 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -2,3 +2,4 @@ Dennis Gilmore <dennis@ausil.us>
 Pavol Babincak <pbabinca@redhat.com>
 Jesse Keating <jkeating@redhat.com>
 Till Maas <opensource@till.name>
+Lubomír Sedlář <lsedlar@redhat.com>
diff --git a/bin/fedpkg b/bin/fedpkg
index f85c789..be16b27 100755
--- a/bin/fedpkg
+++ b/bin/fedpkg
@@ -19,10 +19,28 @@
 set -e
 
 baseurl=http://pkgs.fedoraproject.org/repo/pkgs
-pkgname=$(basename $PWD)
+pkgname=$(basename "$PWD")
 if [[ -s sources ]]; then
-    while read md5sum tarball; do
-        curl -H Pragma: -o ./$tarball -R -S --fail $baseurl/$pkgname/$tarball/$md5sum/$tarball
-    done < sources
-    md5sum -c sources
+    # 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 all hashes are
+        # the same type, so we don't need to read it again for each line.
+        while read -r _ filename _ hash; do
+            # Remove parenthesis around tarball name
+            tarball=${filename:1:-1}
+            curl -H Pragma: -o "./$tarball" -R -S --fail "$baseurl/$pkgname/$tarball/$hashtype/$hash/$tarball"
+        done < sources
+        "${hashtype}sum" -c sources
+    else
+        # Ok, we're working with MD5.
+        while read -r md5sum tarball; do
+            curl -H Pragma: -o "./$tarball" -R -S --fail "$baseurl/$pkgname/$tarball/$md5sum/$tarball"
+        done < sources
+        md5sum -c sources
+    fi
 fi
-- 
2.11.0