summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Wiens <jordan@psifertex.com>2022-01-28 13:19:50 -0500
committerJordan Wiens <jordan@psifertex.com>2022-01-28 13:19:50 -0500
commit4ee98c21c517e40a31d5eb51ef4cee9fe8b4bb7e (patch)
treeef7db5445af182fc2abe1f00e2f78cd60918f0a8
parent6c94811ba217acc3be17b5057928a1adaf7f0ab0 (diff)
add simple hash verifier and renamer
-rwxr-xr-xscripts/verify_hashes.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/verify_hashes.py b/scripts/verify_hashes.py
new file mode 100755
index 00000000..f555d778
--- /dev/null
+++ b/scripts/verify_hashes.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+'''Simple script to verify SHA256 hashes and rename downloaded versions with their version number'''
+import json
+import requests
+import hashlib
+from pathlib import Path
+
+
+class DownloadException(Exception):
+ pass
+
+def sha256(path):
+ with open(filename,"rb") as f:
+ return hashlib.sha256(f.read()).hexdigest()
+
+url = 'https://binary.ninja/js/hashes.json'
+r = requests.get(url)
+results = json.loads(r.text)
+if not results['version']:
+ raise DownloadException('Hash file does not exist or is incomplete.')
+
+version = results["version"]
+for filename in results["hashes"]:
+ hash = results["hashes"][filename]
+ binfile = Path(filename)
+ if binfile.is_file():
+ if sha256(binfile) == hash:
+ newname = f"{filename[0:-4]}-{version}{filename[-4:]}"
+ print(f"SHA256 matches for {filename}, renaming to {newname}")
+ binfile.rename(newname)
+ else:
+ print(f"HASH FAILED for {filename}")
+ else:
+ print(f"No {filename} found")