add md5 checksum support to Install.py for LATTE
This commit is contained in:
@ -4,7 +4,7 @@
|
|||||||
# used to automate the steps described in the README file in this dir
|
# used to automate the steps described in the README file in this dir
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys,os,re,subprocess
|
import sys,os,re,subprocess,hashlib
|
||||||
|
|
||||||
# help message
|
# help message
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ specify one or more options, order does not matter
|
|||||||
-b = download and build the LATTE library
|
-b = download and build the LATTE library
|
||||||
-p = specify folder of existing LATTE installation
|
-p = specify folder of existing LATTE installation
|
||||||
-m = copy Makefile.lammps.suffix to Makefile.lammps
|
-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:
|
Example:
|
||||||
|
|
||||||
@ -36,6 +36,13 @@ make lib-latte args="-p $HOME/latte" # use existing LATTE installation
|
|||||||
|
|
||||||
version = '1.2.1'
|
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
|
# print error message or help
|
||||||
|
|
||||||
def error(str=None):
|
def error(str=None):
|
||||||
@ -91,6 +98,17 @@ def geturl(url,fname):
|
|||||||
error("Failed to download source code with 'curl' or 'wget'")
|
error("Failed to download source code with 'curl' or 'wget'")
|
||||||
return
|
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
|
# parse args
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
@ -144,6 +162,11 @@ if buildflag:
|
|||||||
print("Downloading LATTE ...")
|
print("Downloading LATTE ...")
|
||||||
geturl(url,"LATTE.tar.gz")
|
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 ...")
|
print("Unpacking LATTE ...")
|
||||||
if os.path.exists(lattedir):
|
if os.path.exists(lattedir):
|
||||||
cmd = 'rm -rf "%s"' % lattedir
|
cmd = 'rm -rf "%s"' % lattedir
|
||||||
@ -162,7 +185,7 @@ if buildflag:
|
|||||||
|
|
||||||
# create 3 links in lib/latte to LATTE dirs
|
# create 3 links in lib/latte to LATTE dirs
|
||||||
# do this -b or -p is set
|
# do this -b or -p is set
|
||||||
|
|
||||||
if buildflag or pathflag:
|
if buildflag or pathflag:
|
||||||
print("Creating links to LATTE files")
|
print("Creating links to LATTE files")
|
||||||
if os.path.isfile("includelink") or os.path.islink("includelink"):
|
if os.path.isfile("includelink") or os.path.islink("includelink"):
|
||||||
|
|||||||
Reference in New Issue
Block a user