diff options
Diffstat (limited to 'pcb/download.sh')
-rwxr-xr-x | pcb/download.sh | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/pcb/download.sh b/pcb/download.sh index dfe1be9..4aa5f49 100755 --- a/pcb/download.sh +++ b/pcb/download.sh @@ -1,11 +1,15 @@ #!/bin/sh +# This script creates a cache directory and downloads all external documents +# to this folder. In addition the SHA1 checksums are checked and the user is +# warned if a checksum does not match. + + # constants DOCUMENTS_FILE='documents.tsv' CACHE='./cache' # target folder for all downloads - # strip first line of table file TABLE=$(sed '1d' "${DOCUMENTS_FILE}") @@ -18,14 +22,29 @@ do FILENAME=$(echo "$line" | awk -F '\t' '{print $1}') # column 1 -> filename URL=$(echo "$line" | awk -F '\t' '{print $2}') # column 2 -> URL + SHA1=$(echo "$line" | awk -F '\t' '{print $3}') # column 3 -> SHA1 hash + + FILEPATH="${CACHE}/${FILENAME}" + + # download file if it does not exist in cache + if [ ! -f "${FILEPATH}" ] + then + printf 'Downloading %s ...' "${FILEPATH}" + if wget -qO "${FILEPATH}" "${URL}" 2> /dev/null + then + printf " ok\n" # if wget returned with exit code 0 + else + printf " error!\n" # in any other case + fi + fi - # actual download of one document - printf 'Downloading %s/%s ...' "${CACHE}" "${FILENAME}" - if wget -qO "${CACHE}/${FILENAME}" "${URL}" 2> /dev/null + # generate and compare SHA1 checksum of file + printf 'Checking SHA1 sum of %s ...' "${FILEPATH}" + if printf '%s %s' "${SHA1}" "${FILEPATH}" | sha1sum -c - > /dev/null 2>&1 then - printf " ok\n" # if wget returned with exit code 0 + echo " ok" else - printf " error!\n" # in any other case + echo " file changed!" fi done |