aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2020-07-13 00:36:11 -0400
committerRob Austein <sra@hactrn.net>2020-07-13 00:36:11 -0400
commit4d6f6ceebcb0422bfcf3443e7f4eb7a9eb1e4338 (patch)
tree4cc3ee6c35b659c8cafee076b6931d1d9d922b8b /scripts
parent68f48b7e850de48063d95645c3d76e0a2be5c079 (diff)
Still more fun building packages with Python 3
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-firmware-package.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/scripts/build-firmware-package.py b/scripts/build-firmware-package.py
index 4f078f4..6ce49ab 100755
--- a/scripts/build-firmware-package.py
+++ b/scripts/build-firmware-package.py
@@ -6,6 +6,7 @@ import argparse
import hashlib
import tarfile
import json
+import sys
import os
parser = argparse.ArgumentParser()
@@ -14,8 +15,8 @@ parser.add_argument("firmware", nargs = "+", help = "firmware
args = parser.parse_args()
tar = tarfile.TarFile.open(fileobj = args.tarfile, mode = "w|gz")
-head = subprocess.check_output(("git", "rev-parse", "HEAD")).strip().decode()
-time = subprocess.check_output(("git", "show", "-s", "--format=%ct", "HEAD")).strip().decode()
+head = subprocess.check_output(("git", "rev-parse", "HEAD")).decode().strip()
+time = subprocess.check_output(("git", "show", "-s", "--format=%ct", "HEAD")).decode().strip()
commits = dict((path, hash) for hash, path, branch in
(line.decode().split() for line in subprocess.check_output(("git", "submodule", "status")).splitlines()))
sha256 = {}
@@ -25,20 +26,18 @@ for fn in args.firmware:
sha256[os.path.basename(fn)] = hashlib.sha256(f.read()).hexdigest()
tar.add(fn, os.path.basename(fn))
-with tempfile.NamedTemporaryFile() as f:
+manifest = json.dumps(dict(head = head, time = time, commits = commits, sha256 = sha256), indent = 2, sort_keys = True)
+
+if os.path.isdir(os.getenv("GNUPGHOME", "")):
+ gpg = subprocess.Popen(("gpg", "--clearsign", "--personal-digest-preferences", "SHA256", "--no-permission-warning"),
+ stdin = subprocess.PIPE, stdout = subprocess.PIPE, universal_newlines = True)
+ manifest = gpg.communicate(manifest)[0]
+ if gpg.returncode:
+ sys.exit("gpg failed")
+
+with tempfile.NamedTemporaryFile("w+") as f:
os.fchmod(f.fileno(), 0o644)
- use_gpg = os.path.isdir(os.getenv("GNUPGHOME", ""))
- if use_gpg:
- gpg = subprocess.Popen(("gpg", "--clearsign", "--personal-digest-preferences", "SHA256", "--no-permission-warning"),
- stdin = subprocess.PIPE, stdout = f)
- jf = gpg.stdin
- else:
- jf = f
- jf.write(json.dumps(dict(head = head, time = time, commits = commits, sha256 = sha256), indent = 2).encode())
- if use_gpg:
- gpg.stdin.close()
- if gpg.wait():
- raise subprocess.CalledProcessError(gpg.returncode, "gpg")
+ f.write(manifest)
f.seek(0)
tar.add(f.name, "MANIFEST")