From b7fb31ea760ec8c5745748f45206660b26b58dfb Mon Sep 17 00:00:00 2001 From: KASR Date: Thu, 27 Apr 2023 09:47:50 +0200 Subject: [PATCH] python script to verify the checksum of the llama models Added Python script for verifying SHA256 checksums of files in a directory, which can run on multiple platforms. Improved the formatting of the output results for better readability. --- scripts/verify-checksum-models.py | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 scripts/verify-checksum-models.py diff --git a/scripts/verify-checksum-models.py b/scripts/verify-checksum-models.py new file mode 100644 index 000000000..8963c156d --- /dev/null +++ b/scripts/verify-checksum-models.py @@ -0,0 +1,64 @@ +import os +import hashlib + +# Define the path to the llama directory (parent folder of script directory) +llama_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) + +# Define the file with the list of hashes and filenames +hash_list_file = os.path.join(llama_path, "SHA256SUMS") + +# Check if the hash list file exists +if not os.path.exists(hash_list_file): + print(f"Hash list file not found: {hash_list_file}") + exit(1) + +# Read the hash file content and split it into an array of lines +with open(hash_list_file, "r") as f: + hash_list = f.read().splitlines() + +# Create an array to store the results +results = [] + +# Loop over each line in the hash list +for line in hash_list: + # Split the line into hash and filename + hash_value, filename = line.split(" ") + + # Get the full path of the file by joining the models path and the filename + file_path = os.path.join(llama_path, filename) + + # Informing user of the progress of the integrity check + print(f"Verifying the checksum of {file_path}") + + # Check if the file exists + if os.path.exists(file_path): + # Calculate the SHA256 checksum of the file using hashlib + with open(file_path, "rb") as f: + file_hash = hashlib.sha256(f.read()).hexdigest() + + # Compare the file hash with the expected hash + if file_hash == hash_value: + valid_checksum = "V" + file_missing = "" + else: + valid_checksum = "" + file_missing = "" + else: + valid_checksum = "" + file_missing = "X" + + # Add the results to the array + results.append({ + "filename": filename, + "valid checksum": valid_checksum, + "file missing": file_missing + }) + + +# Print column headers for results table +print("\n" + "filename".ljust(40) + "valid checksum".center(20) + "file missing".center(20)) +print("-" * 80) + +# Output the results as a table +for r in results: + print(f"{r['filename']:40} {r['valid checksum']:^20} {r['file missing']:^20}")