2014-08-19 12:49:45 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# Get the online version of the GnuPG software version database
|
|
|
|
# Copyright (C) 2014 Werner Koch
|
|
|
|
#
|
|
|
|
# This file is free software; as a special exception the author gives
|
|
|
|
# unlimited permission to copy and/or distribute it, with or without
|
|
|
|
# modifications, as long as this notice is preserved.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
|
|
|
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
# The URL of the file to retrieve.
|
2016-05-25 14:44:50 +02:00
|
|
|
urlbase="https://versions.gnupg.org/"
|
2014-08-19 12:49:45 +02:00
|
|
|
|
|
|
|
WGET=wget
|
|
|
|
GPGV=gpgv
|
|
|
|
|
|
|
|
srcdir=$(dirname "$0")
|
|
|
|
distsigkey="$srcdir/../g10/distsigkey.gpg"
|
|
|
|
|
|
|
|
# Convert a 3 part version number it a numeric value.
|
|
|
|
cvtver () {
|
|
|
|
awk 'NR==1 {split($NF,A,".");X=1000000*A[1]+1000*A[2]+A[3];print X;exit 0}'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Prints usage information.
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat <<EOF
|
2024-02-29 15:35:27 +01:00
|
|
|
Usage: $(basename $0) [OPTIONS] [packages]
|
2014-08-19 12:49:45 +02:00
|
|
|
Get the online version of the GnuPG software version database
|
2024-02-29 15:35:27 +01:00
|
|
|
and optionally download packages and verify their signatures.
|
|
|
|
|
2014-08-19 12:49:45 +02:00
|
|
|
Options:
|
2024-02-29 15:35:27 +01:00
|
|
|
--info Print only infos about packages
|
2015-05-12 14:27:14 +02:00
|
|
|
--skip-download Assume download has already been done.
|
|
|
|
--skip-verify Do not check signatures
|
|
|
|
--skip-selfcheck Do not check GnuPG version
|
2024-02-29 10:21:33 +01:00
|
|
|
(default if not used in the GnuPG tree)
|
2015-05-12 14:27:14 +02:00
|
|
|
--find-sha1sum Print the name of the sha1sum utility
|
2016-01-25 09:03:50 +01:00
|
|
|
--find-sha256sum Print the name of the sha256sum utility
|
2015-05-12 14:27:14 +02:00
|
|
|
--help Print this help.
|
2024-02-29 15:35:27 +01:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
getswdb.sh gnupg24 gpgme libksba libassuan
|
|
|
|
|
2014-08-19 12:49:45 +02:00
|
|
|
EOF
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Parse options
|
|
|
|
#
|
|
|
|
skip_download=no
|
2014-11-07 18:20:06 +01:00
|
|
|
skip_verify=no
|
2015-05-12 14:27:14 +02:00
|
|
|
skip_selfcheck=no
|
2014-09-18 16:00:34 +02:00
|
|
|
find_sha1sum=no
|
2016-01-25 09:03:50 +01:00
|
|
|
find_sha256sum=no
|
2024-02-29 15:35:27 +01:00
|
|
|
info_mode=no
|
|
|
|
packages=
|
|
|
|
die=no
|
2014-08-19 12:49:45 +02:00
|
|
|
while test $# -gt 0; do
|
|
|
|
case "$1" in
|
|
|
|
# Set up `optarg'.
|
|
|
|
--*=*)
|
|
|
|
optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
optarg=""
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
--help|-h)
|
|
|
|
usage 0
|
|
|
|
;;
|
|
|
|
--skip-download)
|
|
|
|
skip_download=yes
|
|
|
|
;;
|
2014-11-07 18:20:06 +01:00
|
|
|
--skip-verify)
|
|
|
|
skip_verify=yes
|
|
|
|
;;
|
2015-05-12 14:27:14 +02:00
|
|
|
--skip-selfcheck)
|
|
|
|
skip_selfcheck=yes
|
|
|
|
;;
|
2014-09-18 16:00:34 +02:00
|
|
|
--find-sha1sum)
|
|
|
|
find_sha1sum=yes
|
|
|
|
;;
|
2016-01-25 09:03:50 +01:00
|
|
|
--find-sha256sum)
|
|
|
|
find_sha256sum=yes
|
|
|
|
;;
|
2024-02-29 15:35:27 +01:00
|
|
|
--info)
|
|
|
|
info_mode=yes
|
|
|
|
;;
|
|
|
|
--*)
|
2014-08-19 12:49:45 +02:00
|
|
|
usage 1 1>&2
|
|
|
|
;;
|
2024-02-29 15:35:27 +01:00
|
|
|
*)
|
|
|
|
packages="$packages $1"
|
|
|
|
;;
|
2014-08-19 12:49:45 +02:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2024-02-29 15:35:27 +01:00
|
|
|
|
2014-09-18 16:00:34 +02:00
|
|
|
# Mac OSX has only a shasum and not sha1sum
|
|
|
|
if [ ${find_sha1sum} = yes ]; then
|
|
|
|
for i in sha1sum shasum ; do
|
|
|
|
tmp=$($i </dev/null 2>/dev/null | cut -d ' ' -f1)
|
|
|
|
if [ x"$tmp" = x"da39a3ee5e6b4b0d3255bfef95601890afd80709" ]; then
|
|
|
|
echo "$i"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "false"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-01-25 09:03:50 +01:00
|
|
|
# Mac OSX has only a shasum and not sha256sum
|
|
|
|
if [ ${find_sha256sum} = yes ]; then
|
|
|
|
for i in 'shasum -a 256' sha256sum ; do
|
|
|
|
tmp=$($i </dev/null 2>/dev/null | cut -d ' ' -f1)
|
|
|
|
tmp2="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
|
|
|
if [ x"$tmp" = x"$tmp2" ]; then
|
|
|
|
echo "$i"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "false"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2024-02-29 10:21:33 +01:00
|
|
|
if [ $skip_verify = no ]; then
|
|
|
|
if [ ! -f "$distsigkey" ]; then
|
|
|
|
distsigkey="/usr/local/share/gnupg/distsigkey.gpg"
|
|
|
|
if [ ! -f "$distsigkey" ]; then
|
|
|
|
distsigkey="/usr/share/gnupg/distsigkey.gpg"
|
|
|
|
if [ ! -f "$distsigkey" ]; then
|
|
|
|
echo "no keyring with release keys found!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo "using release keys from $distsigkey" >&2
|
|
|
|
skip_selfcheck=yes
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2014-09-18 16:00:34 +02:00
|
|
|
# Get GnuPG version from VERSION file. For a GIT checkout this means
|
2014-08-19 12:49:45 +02:00
|
|
|
# that ./autogen.sh must have been run first. For a regular tarball
|
|
|
|
# VERSION is always available.
|
2024-02-29 10:21:33 +01:00
|
|
|
if [ $skip_selfcheck = no ]; then
|
|
|
|
if [ ! -f "$srcdir/../VERSION" ]; then
|
2014-08-19 12:49:45 +02:00
|
|
|
echo "VERSION file missing - run autogen.sh first." >&2
|
|
|
|
exit 1
|
2024-02-29 10:21:33 +01:00
|
|
|
fi
|
|
|
|
version=$(cat "$srcdir/../VERSION")
|
|
|
|
else
|
|
|
|
version="0.0.0"
|
2014-08-19 12:49:45 +02:00
|
|
|
fi
|
|
|
|
version_num=$(echo "$version" | cvtver)
|
|
|
|
|
2024-02-29 10:21:33 +01:00
|
|
|
|
2014-11-07 18:20:06 +01:00
|
|
|
if [ $skip_verify = no ]; then
|
|
|
|
if ! $GPGV --version >/dev/null 2>/dev/null ; then
|
|
|
|
echo "command \"gpgv\" is not installed" >&2
|
|
|
|
echo "(please install an older version of GnuPG)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-09-18 16:00:34 +02:00
|
|
|
fi
|
|
|
|
|
2014-08-19 12:49:45 +02:00
|
|
|
#
|
|
|
|
# Download the list and verify.
|
|
|
|
#
|
|
|
|
if [ $skip_download = yes ]; then
|
|
|
|
if [ ! -f swdb.lst ]; then
|
|
|
|
echo "swdb.lst is missing." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-11-07 18:20:06 +01:00
|
|
|
if [ $skip_verify = no ]; then
|
|
|
|
if [ ! -f swdb.lst.sig ]; then
|
2014-08-19 12:49:45 +02:00
|
|
|
echo "swdb.lst.sig is missing." >&2
|
|
|
|
exit 1
|
2014-11-07 18:20:06 +01:00
|
|
|
fi
|
2014-08-19 12:49:45 +02:00
|
|
|
fi
|
|
|
|
else
|
2014-09-18 16:00:34 +02:00
|
|
|
if ! $WGET --version >/dev/null 2>/dev/null ; then
|
|
|
|
echo "command \"wget\" is not installed" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-08-19 12:49:45 +02:00
|
|
|
if ! $WGET -q -O swdb.lst "$urlbase/swdb.lst" ; then
|
|
|
|
echo "download of swdb.lst failed." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-11-07 18:20:06 +01:00
|
|
|
if [ $skip_verify = no ]; then
|
|
|
|
if ! $WGET -q -O swdb.lst.sig "$urlbase/swdb.lst.sig" ; then
|
2014-08-19 12:49:45 +02:00
|
|
|
echo "download of swdb.lst.sig failed." >&2
|
|
|
|
exit 1
|
2014-11-07 18:20:06 +01:00
|
|
|
fi
|
2014-08-19 12:49:45 +02:00
|
|
|
fi
|
|
|
|
fi
|
2014-11-07 18:20:06 +01:00
|
|
|
if [ $skip_verify = no ]; then
|
2024-02-29 15:35:27 +01:00
|
|
|
if ! $GPGV --keyring "$distsigkey" swdb.lst.sig swdb.lst 2>/dev/null; then
|
2014-08-19 12:49:45 +02:00
|
|
|
echo "list of software versions is not valid!" >&2
|
|
|
|
exit 1
|
2024-02-29 15:35:27 +01:00
|
|
|
fi
|
2014-08-19 12:49:45 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check that the online version of GnuPG is not less than this version
|
|
|
|
# to help detect rollback attacks.
|
|
|
|
#
|
2015-05-12 14:27:14 +02:00
|
|
|
if [ $skip_selfcheck = no ]; then
|
2021-04-09 18:51:17 +02:00
|
|
|
gnupg_ver=$(awk '$1=="gnupg24_ver" {print $2;exit}' swdb.lst)
|
2015-05-12 14:27:14 +02:00
|
|
|
if [ -z "$gnupg_ver" ]; then
|
2021-04-09 18:51:17 +02:00
|
|
|
echo "GnuPG 2.4 version info missing in swdb.lst!" >&2
|
2015-05-12 14:27:14 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
gnupg_ver_num=$(echo "$gnupg_ver" | cvtver)
|
|
|
|
if [ $(( $gnupg_ver_num >= $version_num )) = 0 ]; then
|
|
|
|
echo "GnuPG version in swdb.lst is less than this version!" >&2
|
|
|
|
echo " This version: $version" >&2
|
|
|
|
echo " SWDB version: $gnupg_ver" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-08-19 12:49:45 +02:00
|
|
|
fi
|
2024-02-29 15:35:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Download a package and check its signature.
|
|
|
|
download_pkg () {
|
|
|
|
local url="$1"
|
|
|
|
local file="${url##*/}"
|
|
|
|
|
|
|
|
if ! $WGET -q -O - "$url" >"${file}.tmp" ; then
|
|
|
|
echo "download of $file failed." >&2
|
|
|
|
[ -f "${file}.tmp" ] && rm "${file}.tmp"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [ $skip_verify = no ]; then
|
|
|
|
if ! $WGET -q -O - "${url}.sig" >"${file}.tmpsig" ; then
|
|
|
|
echo "download of $file.sig failed." >&2
|
|
|
|
[ -f "${file}.tmpsig" ] && rm "${file}.tmpsig"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if ! $GPGV -q --keyring "$distsigkey" \
|
|
|
|
"${file}.tmpsig" "${file}.tmp" 2>/dev/null; then
|
|
|
|
echo "signature of $file is not valid!" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
mv "${file}.tmpsig" "${file}.sig"
|
|
|
|
else
|
|
|
|
[ -f "${file}.sig" ] && rm "${file}.sig"
|
|
|
|
fi
|
|
|
|
mv "${file}.tmp" "${file}"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baseurl=$(awk '$1=="gpgorg_base" {print $2; exit 0}' swdb.lst)
|
|
|
|
for p in $packages; do
|
|
|
|
pver=$(awk '$1=="'"$p"'_ver" {print $2}' swdb.lst)
|
|
|
|
if [ -z "$pver" ]; then
|
|
|
|
echo "package '$p' not found" >&2
|
|
|
|
die=yes
|
|
|
|
else
|
|
|
|
pdir=$(awk '$1=="'"$p"'_dir" {print $2":"$3":"$4}' swdb.lst)
|
|
|
|
if [ -n "$pdir" ]; then
|
|
|
|
psuf=$(echo "$pdir" | cut -d: -f3)
|
|
|
|
pname=$(echo "$pdir" | cut -d: -f2)
|
|
|
|
pdir=$(echo "$pdir" | cut -d: -f1)
|
|
|
|
else
|
|
|
|
psuf=
|
|
|
|
pdir="$p"
|
|
|
|
pname="$p"
|
|
|
|
fi
|
|
|
|
if [ -z "$psuf" ]; then
|
|
|
|
psuf=$(awk 'BEGIN {suf="bz2"};
|
|
|
|
$1=="'"$p"'_sha1_gz" {suf="gz"; exit 0};
|
|
|
|
$1=="'"$p"'_sha1_xz" {suf"xz"; exit 0};
|
|
|
|
END {print suf}' swdb.lst)
|
|
|
|
fi
|
|
|
|
pfullname="$pname-$pver.tar.$psuf"
|
|
|
|
if [ $info_mode = yes ]; then
|
|
|
|
echo "$baseurl/$pdir/$pfullname"
|
|
|
|
else
|
|
|
|
echo "downloading $pfullname"
|
|
|
|
download_pkg "$baseurl/$pdir/$pfullname" || die=yes
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ $die = yes ]; then
|
|
|
|
echo "errors found!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
exit 0
|