3333 }
3434fi
3535
36- if [ " $( uname) " = Darwin ]; then
37- MD5=" md5 -r"
38- else
39- MD5=md5sum
40- fi
36+ # shasum is supported on Linux and Darwin
37+ SHA512=" shasum -a 512"
4138
42- calcmd5 () {
39+ calcsha512 () {
4340 local file=" $1 "
44- local md5 =" $2 "
45- local file_md5
46- file_md5 =$( ${MD5 } " $file " | cut -d\ -f1)
41+ local sha512 =" $2 "
42+ local file_sha512
43+ file_sha512 =$( ${SHA512 } " $file " | cut -d\ -f1)
4744
48- test " $md5 " = " $file_md5 "
45+ test " $sha512 " = " $file_sha512 "
4946}
5047
5148downloader () {
@@ -61,24 +58,24 @@ downloader() {
6158
6259download () {
6360 local url=" $2 "
64- local _md5 =" $3 "
61+ local _sha512 =" $3 "
6562 local basename_url
6663 basename_url=" $( basename " ${url} " ) "
6764 local target=" ${1:- " ${basename_url} " } "
6865
69- if [ -f " $target " ] && [ -n " $_md5 " ]; then
70- # if our target file exists and an MD5 sum was given, check it's MD5
71- calcmd5 " $target " " $_md5 " && {
72- _echo " $0 : target exists, md5 matches."
66+ if [ -f " $target " ] && [ -n " $_sha512 " ]; then
67+ # if our target file exists and an SHA512 sum was given, check it's SHA512
68+ calcsha512 " $target " " $_sha512 " && {
69+ _echo " $0 : target exists, SHA512 matches."
7370 exit 0
7471 }
7572 fi
7673
7774 local filename
7875 filename=" $( basename " $url " ) "
7976 [ -f " $DLCACHE_DIR /$filename " ] && {
80- # if the file exists in cache, check it's md5 and possibly remove it.
81- if calcmd5 " $DLCACHE_DIR /$filename " " $_md5 " ; then
77+ # if the file exists in cache, check it's SHA512 and possibly remove it.
78+ if calcsha512 " $DLCACHE_DIR /$filename " " $_sha512 " ; then
8279 _echo " $0 : getting \" $url \" from cache"
8380 else
8481 _echo " $0 : \" $DLCACHE_DIR /$filename \" has wrong or no checksum, re-downloading"
@@ -96,8 +93,8 @@ download() {
9693 }
9794
9895 # only try to calculate the checksum if a checksum was given
99- if [ -n " $_md5 " ]; then
100- calcmd5 " $DLCACHE_DIR /$filename " " $_md5 " || {
96+ if [ -n " $_sha512 " ]; then
97+ calcsha512 " $DLCACHE_DIR /$filename " " $_sha512 " || {
10198 _echo " $0 : checksum mismatch!"
10299 exit 1
103100 }
0 commit comments