aboutsummaryrefslogtreecommitdiff
path: root/build-homebrew-formula.py
blob: 8f29720f42d628ea911e5a3a36ac1940fd7d860c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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))