add md5 checksum support to Install.py for LATTE

This commit is contained in:
Axel Kohlmeyer 2018-06-27 16:52:28 -04:00
parent 49a91db0b2
commit 08552fefe9
1 changed files with 26 additions and 3 deletions

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir
from __future__ import print_function
import sys,os,re,subprocess
import sys,os,re,subprocess,hashlib
# help message
@ -24,7 +24,7 @@ specify one or more options, order does not matter
-b = download and build the LATTE library
-p = specify folder of existing LATTE installation
-m = copy Makefile.lammps.suffix to Makefile.lammps
-v = set version of LATTE library to download and set up (default = 1.1.1)
-v = set version of LATTE library to download and set up (default = 1.2.1)
Example:
@ -36,6 +36,13 @@ make lib-latte args="-p $HOME/latte" # use existing LATTE installation
version = '1.2.1'
# known checksums for different LATTE versions. used to validate the download.
checksums = { \
'1.1.0' : '533635721ee222d0ed2925a18fb5b294', \
'1.2.0' : '68bf0db879da5e068a71281020239ae7', \
'1.2.1' : 'bed76e7e76c545c36dd848a8f1fd35eb' \
}
# print error message or help
def error(str=None):
@ -91,6 +98,17 @@ def geturl(url,fname):
error("Failed to download source code with 'curl' or 'wget'")
return
def checkmd5sum(md5sum,fname):
with open(fname,'rb') as fh:
m = hashlib.md5()
while True:
data = fh.read(81920)
if not data:
break
m.update(data)
fh.close()
return m.hexdigest() == md5sum
# parse args
args = sys.argv[1:]
@ -144,6 +162,11 @@ if buildflag:
print("Downloading LATTE ...")
geturl(url,"LATTE.tar.gz")
# verify downloaded archive integrity via md5 checksum, if known.
if version in checksums:
if not checkmd5sum(checksums[version],'LATTE.tar.gz'):
error("Checksum for LATTE library does not match")
print("Unpacking LATTE ...")
if os.path.exists(lattedir):
cmd = 'rm -rf "%s"' % lattedir
@ -162,7 +185,7 @@ if buildflag:
# create 3 links in lib/latte to LATTE dirs
# do this -b or -p is set
if buildflag or pathflag:
print("Creating links to LATTE files")
if os.path.isfile("includelink") or os.path.islink("includelink"):