Skip to content

Commit

Permalink
Test downloading.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Oct 20, 2024
1 parent 1bcaa7d commit 074bbc1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:

- run: futhark test -C --pass-compiler-option=--Werror *

# - run: ./get-data.sh external-data.txt
- run: ./get-data.sh -t external-data.txt
25 changes: 19 additions & 6 deletions get-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ set -o errexit
set -o pipefail
set -o nounset

if [ "$#" -ne "1" ]; then
echo "Usage: $0 FILE"
if [ "$#" -ne "1" ] && [ "$#" -ne "2" ] || [ "x$2" -ne "x-t" ]; then
echo "Usage: $0 [-t] FILE"
echo "FILE must be a file containing lines of the format:"
echo " PATH URL SHA256SUM"
echo "$0 will attempt to download the file at URL into PATH (relative to"
echo "the location of external-data.txt) after verifying that the sha256sum is"
echo "identical to SHA256SUM. Neither field can contain spaces."
echo "If -t is passed, delete the file after downloading it. This is used for testing."

exit 3
fi
Expand All @@ -37,11 +38,20 @@ if [ -z "$(which curl)" ]; then
exit 5
fi

function longest_line() { cat "$1" | awk '{print length($1)}' | sort -nr | head -1 ; }
DELETE=false

BASEDIR=$(dirname "$1")
if [ "$#" -eq "1" ]; then
FILE=$1
elif [ "$#" -eq "2" ]; then
FILE=$2
DELETE=true
fi

function longest_line() { cat "$FILE" | awk '{print length($FILE)}' | sort -nr | head -1 ; }

n=$(longest_line "$1")
BASEDIR=$(dirname "$FILE")

n=$(longest_line "$FILE")

while read -r OUTPUT URL CHECKSUM; do
printf "%-${n}s: " "$OUTPUT"
Expand Down Expand Up @@ -71,6 +81,9 @@ while read -r OUTPUT URL CHECKSUM; do
echo "Got: $COMPUTED_SUM"
exit 1
fi
done < "$1"
if [ "$DELETE" = "true" ]; then
rm -f "${BASEDIR}/${OUTPUT}"
fi
done < "$FILE"

echo "Done."

0 comments on commit 074bbc1

Please sign in to comment.