diff options
author | xengineering <me@xengineering.eu> | 2022-01-24 16:32:04 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2022-01-24 16:32:04 +0100 |
commit | 2018ed033b58da6808d28fe76ff7b3005592e88d (patch) | |
tree | 12644b73e7dcb3f8061b394e859c544398148a7d /pcb/download.sh | |
parent | e32f29914ea3d1ac4bc0682d11b9302227c3b382 (diff) | |
download | ledcontrol-2018ed033b58da6808d28fe76ff7b3005592e88d.tar ledcontrol-2018ed033b58da6808d28fe76ff7b3005592e88d.tar.zst ledcontrol-2018ed033b58da6808d28fe76ff7b3005592e88d.zip |
Implement SHA1 checksums and optional download for documents
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 |