From 9faf6f071cbb75432bfbc7fb7286d49eb2ba8512 Mon Sep 17 00:00:00 2001
From: Jan Buethe <jbuethe@amazon.de>
Date: Sat, 20 Apr 2024 07:57:52 +0200
Subject: [PATCH] added sha256 check for downloaded data

---
 autogen.sh            |  2 +-
 dnn/download_model.sh | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/autogen.sh b/autogen.sh
index 2b3c1e9ee..774f01513 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -9,7 +9,7 @@ set -e
 srcdir=`dirname $0`
 test -n "$srcdir" && cd "$srcdir"
 
-dnn/download_model.sh "735117b"
+dnn/download_model.sh "8f34305a299183509d22c7ba66790f67916a0fc56028ebd4c8f7b938458f2801"
 
 echo "Updating build configuration files, please wait...."
 
diff --git a/dnn/download_model.sh b/dnn/download_model.sh
index 127441dee..083cf7536 100755
--- a/dnn/download_model.sh
+++ b/dnn/download_model.sh
@@ -7,4 +7,25 @@ if [ ! -f $model ]; then
         echo "Downloading latest model"
         wget https://media.xiph.org/opus/models/$model
 fi
+
+SHA256=$(command -v sha256sum)
+if [ "$?" != "0" ]
+then
+   echo "Could not find sha256 sum. Skipping verification. Please verify manually that sha256 hash of ${model} matches ${1}."
+else
+   echo "Validating checksum"
+   checksum=$1
+   checksum2=$(sha256sum $model | awk '{print $1}')
+   if [ "$checksum" != "$checksum2" ]
+   then
+      echo "checksums don't match, aborting"
+      exit 1
+   else
+      echo "checksums match"
+   fi
+
+fi
+
+
+
 tar xvomf $model
-- 
GitLab