]> https://gitweb.dealii.org/ - candi.git/commitdiff
Update checksum verification (#187)
authorFabian Castelli <50630942+gfcas@users.noreply.github.com>
Thu, 17 Jun 2021 21:06:03 +0000 (23:06 +0200)
committerGitHub <noreply@github.com>
Thu, 17 Jun 2021 21:06:03 +0000 (23:06 +0200)
* Update checksum verification

* Minor corrections

candi.sh
deal.II-toolchain/packages/p4est.package

index fb2689976459d775ae51e7c03dd5ce98d2bf5607..b1610218c0559d8240e8b08ccf952da7ed3182a2 100755 (executable)
--- a/candi.sh
+++ b/candi.sh
@@ -202,7 +202,12 @@ quit_if_fail() {
 #  return 1: No checksum provided          (archive found, but unable to verify)
 #  return 2: ARCHIVE_FILE not found        (archive NOT found)
 #  return 3: CHECKSUM mismatch             (archive file corrupted)
-#  return 4: Neither md5 nor md5sum found  (archive found, but unable to verify)
+#  return 4: Not able to compute checksum  (archive found, but unable to verify)
+#  return 5: Checksum algorithm not found  (archive found, but unable to verify)
+# This function tries to verify the downloaded archive by determing and
+# comparing checksums. For a specific package several checksums might be
+# defined. Based on the length of the given checksum the underlying algorithm
+# is determined. The first matching checksum verifies the archive.
 verify_archive() {
     ARCHIVE_FILE=$1
 
@@ -222,34 +227,64 @@ verify_archive() {
         return 1
     fi
 
-    # Skip verifying archive, if CHECKSUM=ignore
-    if [ "${CHECKSUM}" = "ignore" ]; then
+    # Skip verifying archive, if CHECKSUM=skip
+    if [ "${CHECKSUM}" = "skip" ]; then
         cecho ${WARN} "Skipped checksum check for ${ARCHIVE_FILE}"
         return 1
     fi
 
     cecho ${INFO} "Verifying ${ARCHIVE_FILE}"
 
-    # Verify CHECKSUM using md5/md5sum
-    if builtin command -v md5 > /dev/null; then
-       CURRENT="$(md5 -q ${ARCHIVE_FILE})"
-    elif builtin command -v md5sum > /dev/null; then
-       CURRENT=$(md5sum ${ARCHIVE_FILE} | awk '{print $1}')
-    else
-        cecho ${BAD} "Neither md5 nor md5sum were found in the PATH"
-        return 4
-    fi
-
     for CHECK in ${CHECKSUM}; do
+        # Verify CHECKSUM using md5/sha1/sha256
+        if [ ${#CHECK} = 32 ]; then
+            ALGORITHM="md5"
+            if builtin command -v md5sum > /dev/null; then
+                CURRENT=$(md5sum ${ARCHIVE_FILE} | awk '{print $1}')
+            elif builtin command -v md5 > /dev/null; then
+                CURRENT="$(md5 -q ${ARCHIVE_FILE})"
+            else
+                cecho ${BAD} "Neither md5sum nor md5 were found in the PATH"
+                return 4
+            fi
+        elif [ ${#CHECK} = 40 ]; then
+            ALGORITHM="sha1"
+            if builtin command -v sha1sum > /dev/null; then
+                CURRENT=$(sha1sum ${ARCHIVE_FILE} | awk '{print $1}')
+            elif builtin command -v shasum > /dev/null; then
+                CURRENT=$(shasum -a 1 ${ARCHIVE_FILE} | awk '{print $1}')
+            else
+                cecho ${BAD} "Neither sha1sum nor shasum were found in the PATH"
+                return 4
+            fi
+        elif [ ${#CHECK} = 64 ]; then
+            ALGORITHM="sha256"
+            if builtin command -v sha256sum > /dev/null; then
+                CURRENT=$(sha256sum ${ARCHIVE_FILE} | awk '{print $1}')
+            elif builtin command -v shasum > /dev/null; then
+                CURRENT=$(shasum -a 256 ${ARCHIVE_FILE} | awk '{print $1}')
+            else
+                cecho ${BAD} "Neither sha256sum nor shasum were found in the PATH"
+                return 4
+            fi
+        else
+            cecho ${BAD} "Checksum algorithm could not be determined"
+            exit 5
+        fi
+
         test "${CHECK}" = "${CURRENT}"
         if [ $? = 0 ]; then
-            echo "${ARCHIVE_FILE}: OK"
+            cecho ${GOOD} "${ARCHIVE_FILE}: OK(${ALGORITHM})"
             return 0
-       fi
+        else
+            cecho ${BAD} "${ARCHIVE_FILE}: FAILED(${ALGORITHM})"
+            cecho ${BAD} "${CURRENT} does not match given checksum ${CHECK}"
+        fi
     done
+    unset ALGORITHM
 
     cecho ${BAD} "${ARCHIVE_FILE}: FAILED"
-    cecho ${BAD} "${CURRENT} does not match any in ${CHECKSUM}"
+    cecho ${BAD} "Checksum does not match any in ${CHECKSUM}"
     return 3
 }
 
@@ -313,7 +348,7 @@ download_archive () {
         verify_archive ${ARCHIVE_FILE}
         archive_state=$?
         if [ ${archive_state} = 0 ] || [ ${archive_state} = 1 ] || [ ${archive_state} = 4 ]; then
-            # If the download was successful, and the CHECKSUM is matching, ignored, or not possible
+            # If the download was successful, and the CHECKSUM is matching, skipped, or not possible
             return 0;
         fi
         unset archive_state
index 578dd0a0c8d2e358e97dd2990140a21b483d773e..ecdfbd23c2b9ac05239a038be0a1545f97e5a1d7 100644 (file)
@@ -1,6 +1,10 @@
 #VERSION=1.1;CHECKSUM=37ba7f4410958cfb38a2140339dbf64f
 #VERSION=2.0;CHECKSUM=1b7440a78a28ebf713361acfea70ee78
-VERSION=2.2;CHECKSUM=6943949a6678589ebf1686ee7bad7ea1
+
+VERSION=2.2
+CHECKSUM=1549cbeba29bee2c35e7cc50a90a04961da5f23b6eada9c8047f511b90a8e438
+CHECKSUM="${CHECKSUM} 28cbaf51a335c8cc8e78bb38bbb99251ba7ebf80"
+CHECKSUM="${CHECKSUM} 6943949a6678589ebf1686ee7bad7ea1"
 
 NAME=p4est-$VERSION
 EXTRACTSTO=p4est-${VERSION}

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.