aboutsummaryrefslogtreecommitdiff
path: root/build-homebrew-formula.py
diff options
context:
space:
mode:
Diffstat (limited to 'build-homebrew-formula.py')
-rwxr-xr-xbuild-homebrew-formula.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/build-homebrew-formula.py b/build-homebrew-formula.py
new file mode 100755
index 0000000..8f29720
--- /dev/null
+++ b/build-homebrew-formula.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+# Yes, this is a Python program writing a Ruby program.
+
+import argparse
+import hashlib
+import sys
+import os
+
+parser = argparse.ArgumentParser()
+parser.add_argument("--url-base", default = "https://brew.cryptech.is/tarballs/")
+parser.add_argument("tarball")
+parser.add_argument("version")
+parser.add_argument("formula", type = argparse.FileType("w"), nargs = "?", default = sys.stdout)
+args = parser.parse_args()
+
+template = '''\
+# This Homebrew forumula was automatically generated by a script.
+# You might not want to edit it manually.
+
+class CryptechAlpha < Formula
+
+ desc "Software for working with Cryptech Alpha board HSM"
+ homepage "https://cryptech.is/"
+ version "{version}"
+ url "{url}"
+ sha256 "{sha256}"
+
+ # Eventually we'll want resource clauses here to pull in stuff we
+ # need from pypi, see brew doc for that, but skip it initially.
+
+ # We should also specify a dependency on sqlite3, and perhaps other
+ # packages. Skip that for now too.
+
+ # If we get really ambitous, it would be nice to have "bottled"
+ # (precompiled binary) versions, but that requires either a build
+ # farm or some kind of cross-compilation.
+
+ def install
+ ENV.deparallelize
+ system "make", "-C", "sw/pkcs11"
+ share.install "cryptech-alpha-firmware.tar.gz"
+ lib.install "sw/pkcs11/libpkcs11.dylib"
+ sbin.install "sw/pkcs11/p11util"
+ sbin.install "sw/stm32/projects/hsm/cryptech_upload"
+ end
+
+end
+'''
+
+with open(args.tarball, "rb") as f:
+ digest = hashlib.sha256(f.read()).hexdigest()
+
+args.formula.write(template.format(
+ version = args.version,
+ url = os.path.join(args.url_base, os.path.basename(args.tarball)),
+ sha256 = digest))