COMMON: Enhance verification process to handle more methods

This commit is contained in:
Le Philousophe
2020-03-28 10:18:08 +00:00
parent a47d026ec5
commit 6619aba2ff
2 changed files with 39 additions and 7 deletions
+38 -6
View File
@@ -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
@@ -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