Commit 08552fef authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

add md5 checksum support to Install.py for LATTE

parent 49a91db0
Loading
Loading
Loading
Loading
+26 −3
Original line number Diff line number Diff line
@@ -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