Skip to content

Commit

Permalink
Make the get/extract tarball more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
fauust committed Apr 10, 2024
1 parent 970354e commit 9820116
Showing 1 changed file with 62 additions and 18 deletions.
80 changes: 62 additions & 18 deletions script_templates/get_tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,76 @@ typeset -r mariadb_version="%(prop:mariadb_version)s"

artifacts_url=${ARTIFACTS_URL:-https://ci.mariadb.org}

command -v wget >/dev/null ||
err "wget command not found"
for cmd in awk wget sha256sum; do
command -v $cmd >/dev/null ||
err "$cmd command not found"
done

[[ -d $d ]] || mkdir $d
tarball="${mariadb_version}.tar.gz"
f="${tarbuildnum}/$tarball"

# Do not use flock for AIX/MacOS/FreeBSD
os=$(uname -s)
use_flock=""
if [[ $os != "AIX" && $os != "Darwin" && $os != "FreeBSD" ]]; then
use_flock="flock $d/$tarball"
fi
cmd="$use_flock wget --progress=bar:force:noscroll -cO $d/$tarball $artifacts_url/$f"
verify_checksum() {
echo "verify checksum"
checksum=$(wget -qO- "$artifacts_url/$tarbuildnum/sha256sums.txt" | awk '{print $1}')
checksum_file=$(sha256sum "$1" | awk '{print $1}')

res=1
for i in {1..10}; do
if eval "$cmd"; then
res=0
break
if [[ "$checksum_file" == "$checksum" ]]; then
echo "checksum match"
return 0
else
sleep "$i"
echo "checksum does not match"
return 1
fi
}

download_tarball() {
# Do not use flock for AIX/MacOS/FreeBSD
os=$(uname -s)
use_flock=""
if [[ $os != "AIX" && $os != "Darwin" && $os != "FreeBSD" ]]; then
use_flock="flock $d/$tarball"
fi
cmd="$use_flock wget --progress=bar:force:noscroll -cO $d/$tarball $artifacts_url/$f"

res=1
for i in {1..10}; do
if eval "$cmd"; then
res=0
break
else
sleep "$i"
fi
done
if ((res != 0)); then
err "download tarball failed"
fi
}

if [[ -f $d/$tarball ]]; then
echo "$d/$tarball already present"
if verify_checksum "$d/$tarball"; then
true
else
echo "download tarball again"
rm -f $d/$tarball
download_tarball
if verify_checksum "$d/$tarball"; then
true
else
err "checksum does not match, aborting"
fi
fi
else
echo "$d/$tarball does not exist, download tarball"
download_tarball
if verify_checksum "$d/$tarball"; then
true
else
err "checksum does not match, aborting"
fi
done
if ((res != 0)); then
exit $res
fi

echo "extract $d/$tarball"
tar -xzf $d/$tarball --strip-components=1
echo "done"

0 comments on commit 9820116

Please sign in to comment.