From 2018ed033b58da6808d28fe76ff7b3005592e88d Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 24 Jan 2022 16:32:04 +0100 Subject: Implement SHA1 checksums and optional download for documents --- pcb/documents.tsv | 14 +++++++------- pcb/download.sh | 31 +++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/pcb/documents.tsv b/pcb/documents.tsv index 087fc3d..2544bc3 100644 --- a/pcb/documents.tsv +++ b/pcb/documents.tsv @@ -1,7 +1,7 @@ -Name URL -IRF840A_datasheet.pdf https://www.infineon.com/dgdl/Infineon-SPP_A04N50C3-DS-v02_09-en.pdf?fileId=db3a304412b407950112b42cfc9247e4 -IR2127_datasheet.pdf https://www.infineon.com/dgdl/Infineon-ir2127-DS-v01_00-EN.pdf?fileId=5546d462533600a4015355c868861696 -L7805CV_datasheet.pdf https://www.st.com/resource/en/datasheet/l78.pdf -STM32F103C8T6_datasheet.pdf https://www.st.com/resource/en/datasheet/stm32f103c8.pdf -STM32F103C8T6_reference_manual.pdf https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf -STM32F103C8T6_programming_manual.pdf https://www.st.com/resource/en/programming_manual/pm0056-stm32f10xxx20xxx21xxxl1xxxx-cortexm3-programming-manual-stmicroelectronics.pdf +Name URL SHA1 +IRF840A_datasheet.pdf https://www.infineon.com/dgdl/Infineon-SPP_A04N50C3-DS-v02_09-en.pdf?fileId=db3a304412b407950112b42cfc9247e4 02a02be50e00a6d88f29ed5390b41e00ff18f377 +IR2127_datasheet.pdf https://www.infineon.com/dgdl/Infineon-ir2127-DS-v01_00-EN.pdf?fileId=5546d462533600a4015355c868861696 08b47f0b650bb8aee3aa8ab94e928d3ef6a2d23b +L7805CV_datasheet.pdf https://www.st.com/resource/en/datasheet/l78.pdf 751385ffecbf704a5b48e3f0338207634aba3bbe +STM32F103C8T6_datasheet.pdf https://www.st.com/resource/en/datasheet/stm32f103c8.pdf cef117449ee60efe80f4b927569ee03f5a8ed0b9 +STM32F103C8T6_reference_manual.pdf https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf adbb749261c5db0ecbec95c9e63071737d91a878 +STM32F103C8T6_programming_manual.pdf https://www.st.com/resource/en/programming_manual/pm0056-stm32f10xxx20xxx21xxxl1xxxx-cortexm3-programming-manual-stmicroelectronics.pdf befb4158d0f1317f411c829adcadeebf09e2d7a8 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 -- cgit v1.2.3-70-g09d2