aboutsummaryrefslogtreecommitdiff
path: root/firmware/build-package.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-06-27 11:38:50 -0400
committerRob Austein <sra@hactrn.net>2016-06-27 11:38:50 -0400
commitf7aa0ad426ddfc01f66212a6c4f5cf352400faf2 (patch)
treed55c2e73cb20ade58880123f143ac4e51e911794 /firmware/build-package.py
parent5ce361bac89d49a368350e8c475b83e8e6cf0718 (diff)
parenteab67430dc2816993880b4bce0a4639440a12fb7 (diff)
Merged firmware/master.
Diffstat (limited to 'firmware/build-package.py')
-rwxr-xr-xfirmware/build-package.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/firmware/build-package.py b/firmware/build-package.py
new file mode 100755
index 0000000..0df116b
--- /dev/null
+++ b/firmware/build-package.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+import subprocess
+import tempfile
+import argparse
+import hashlib
+import tarfile
+import json
+import os
+
+parser = argparse.ArgumentParser()
+parser.add_argument("tarfile", type = argparse.FileType("wb"), help = "tarball to create")
+parser.add_argument("firmware", nargs = "+", help = "firmware files to stuff into tarball")
+args = parser.parse_args()
+
+tar = tarfile.TarFile(mode = "w", fileobj = args.tarfile)
+head = subprocess.check_output(("git", "rev-parse", "HEAD")).strip()
+time = subprocess.check_output(("git", "show", "-s", "--format=%ct", "HEAD")).strip()
+commits = [line.split() for line in subprocess.check_output(("git", "submodule", "status")).splitlines()]
+sha256 = {}
+
+for fn in args.firmware:
+ with open(fn, "rb") as f:
+ sha256[os.path.basename(fn)] = hashlib.sha256(f.read()).hexdigest()
+ tar.add(fn, os.path.basename(fn))
+
+with tempfile.NamedTemporaryFile() as f:
+ gpg = subprocess.Popen(("gpg", "--clearsign", "--personal-digest-preferences", "SHA256", "--no-permission-warning"),
+ stdin = subprocess.PIPE, stdout = f)
+ json.dump(dict(head = head, time = time, commits = commits, sha256 = sha256), gpg.stdin, indent = 2)
+ gpg.stdin.close()
+ if gpg.wait():
+ raise subprocess.CalledProcessError(gpg.returncode, "gpg")
+ tar.add(f.name, "MANIFEST")