Skip to content

Commit 2a4061e

Browse files
authored
Merge pull request #2116 from apache/fix_verify_checksums.sh
Fix verify_checksums.sh
2 parents ae6e522 + 5312d75 commit 2a4061e

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

dist/verify_checksums.sh

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,34 @@ TMP_DIR=$(mktemp -d)
3030
# TODO: Use json endpoint + jq to parse out the url
3131
# https://pypi.org/pypi/apache-libcloud/3.4.0/json
3232
EXTENSIONS[0]=".tar.gz"
33-
EXTENSIONS[1]="-py2.py3-none-any.whl"
33+
EXTENSIONS[1]=".whl"
3434

35-
APACHE_MIRROR_URL="http://www.apache.org/dist/libcloud"
36-
PYPI_MIRROR_URL_SOURCE="https://pypi.python.org/packages/source/a/apache-libcloud"
37-
PYPI_SIMPLE_URL="https://pypi.org/simple/apache-libcloud/"
35+
# Get the download URL for the given extension from PyPi JSON API
36+
function get_pypi_url() {
37+
local extension=$1
38+
local pypi_version
39+
40+
pypi_version=$(echo "${VERSION}" | sed -E "s/^apache[-_]libcloud-//")
41+
42+
curl -s "https://pypi.org/pypi/apache-libcloud/${pypi_version}/json" | \
43+
jq -r --arg ext "${extension}" \
44+
'.urls[] | select(.filename | endswith($ext)) | .url' | \
45+
head -n 1
46+
}
47+
48+
# Get the download URL for the given extension from Apache mirror
49+
function get_apache_url() {
50+
local extension=$1
51+
local apache_version
52+
53+
apache_version=$(echo "${VERSION}" | sed -E "s/^apache[-_]libcloud-//")
54+
55+
# List files from Apache directory and find the matching file
56+
curl -s "https://downloads.apache.org/libcloud/" | \
57+
grep -oP "href=\"\K[^\"]*-${apache_version}[^\"]*${extension}" | \
58+
head -n 1 | \
59+
sed "s|^|https://downloads.apache.org/libcloud/|"
60+
}
3861

3962
# From http://tldp.org/LDP/abs/html/debugging.html#ASSERT
4063
function assert () # If condition false,
@@ -69,19 +92,17 @@ do
6992
extension=${EXTENSIONS[$i]}
7093
file_name="${VERSION}${extension}"
7194

72-
if [ "${extension}" = "-py2.py3-none-any.whl" ]; then
95+
if [ "${extension}" = ".whl" ]; then
7396
# shellcheck disable=SC2001
7497
file_name=$(echo "${file_name}" | sed "s/apache-libcloud/apache_libcloud/g")
7598
fi
7699

77-
apache_url="${APACHE_MIRROR_URL}/${file_name}"
78-
pypi_url="${PYPI_MIRROR_URL}/${file_name}"
100+
apache_url=$(get_apache_url "${extension}")
101+
pypi_url=$(get_pypi_url "${extension}")
79102

80-
if [ "${extension}" = "-py2.py3-none-any.whl" ]; then
81-
# Get the wheel full URL from PyPi Simple index
82-
pypi_url=$(curl -s ${PYPI_SIMPLE_URL} | grep "${file_name}" | sed -n 's/.*href="\([^"]*\)".*/\1/p')
83-
else
84-
pypi_url="${PYPI_MIRROR_URL_SOURCE}/${file_name}"
103+
if [ -z "${pypi_url}" ]; then
104+
echo "[ERR] Failed to resolve PyPi URL for ${file_name}"
105+
exit 2
85106
fi
86107

87108
assert "${apache_url} != ${pypi_url}", "URLs must be different"

0 commit comments

Comments
 (0)