From 6619aba2ff0bedeacb84834fd8e2629e8ffbd598 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Sat, 28 Mar 2020 09:55:30 +0000 Subject: [PATCH] COMMON: Enhance verification process to handle more methods --- toolchains/common/functions.sh | 44 ++++++++++++++++--- .../windows-x86_64/packages/libsdl2/build.sh | 2 +- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/toolchains/common/functions.sh b/toolchains/common/functions.sh index 0720fc6..4d8d573 100755 --- a/toolchains/common/functions.sh +++ b/toolchains/common/functions.sh @@ -22,6 +22,42 @@ __do_patch () { fi } +# This function is a private helper and should not be unprefixed +__do_verify () { + local hsh + + if [ -z "$2" ]; then + # No verification method + return + fi + + case $2 in + 'gpgurl:'*) + wget --no-hsts --progress=dot "${2#gpgurl:}" -O "$1.sig" + if gpg --verify "$1.sig" "$1"; then + return + fi + ;; + 'sha1:'*) + hsh=$(sha1sum "$1" |cut -f1 -d' ') + if [ "$hsh" = "${2#sha1:}" ]; then + return + fi + ;; + 'sha256:'*) + hsh=$(sha256sum "$1" |cut -f1 -d' ') + if [ "$hsh" = "${2#sha256:}" ]; then + return + fi + ;; + *) + error "Verification method not supported: $2" + ;; + esac + + error "BUG" +} + __do_pkg_fetch () { if [ -d "$1"*/ ]; then rm -rf "$1"*/ @@ -41,12 +77,8 @@ __do_http_fetch () { fname=$(basename $2) wget --no-hsts --progress=dot "$2" -O "$fname" - if [ -n "$4" ]; then - wget --no-hsts --progress=dot "$4" -O "$fname.sig" - if ! gpg --verify "$fname.sig" "$fname"; then - exit 1 - fi - fi + __do_verify "$fname" "$4" + $3 "$fname" cd "$1"*/ do_patch diff --git a/toolchains/windows-x86_64/packages/libsdl2/build.sh b/toolchains/windows-x86_64/packages/libsdl2/build.sh index 2c8a64f..4ca2628 100755 --- a/toolchains/windows-x86_64/packages/libsdl2/build.sh +++ b/toolchains/windows-x86_64/packages/libsdl2/build.sh @@ -10,7 +10,7 @@ do_make_bdir # GPG key of Sam Lantinga gpg --keyserver hkps://hkps.pool.sks-keyservers.net --recv-keys 0xA7763BE6 -do_http_fetch SDL2 'https://www.libsdl.org/release/SDL2-2.0.10.tar.gz' 'tar xzf' 'https://www.libsdl.org/release/SDL2-2.0.10.tar.gz.sig' +do_http_fetch SDL2 'https://www.libsdl.org/release/SDL2-2.0.10.tar.gz' 'tar xzf' 'gpgurl:https://www.libsdl.org/release/SDL2-2.0.10.tar.gz.sig' rm -Rf $HOME/.gnupg do_configure --enable-shared --disable-static