summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py61
1 files changed, 60 insertions, 1 deletions
diff --git a/setup.py b/setup.py
index 3d12db64..bb1937cc 100755
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,9 @@ Setup file for bitmask.
"""
from __future__ import print_function
+import hashlib
import sys
+import os
import re
if not sys.version_info[0] == 2:
@@ -34,7 +36,6 @@ except ImportError:
from pkg import distribute_setup
distribute_setup.use_setuptools()
from setuptools import setup, find_packages
-import os
from pkg import utils
@@ -168,6 +169,64 @@ class cmd_develop(_develop):
cmdclass["develop"] = cmd_develop
+
+class cmd_binary_hash(Command):
+ """
+ Update the _binaries.py file with hashes for the different helpers.
+ This is used from within the bundle.
+ """
+
+ user_options = []
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self, *args):
+
+ OPENVPN_BIN = os.environ.get('OPENVPN_BIN', None)
+ BITMASK_ROOT = os.environ.get('BITMASK_ROOT', None)
+
+ def exit():
+ print("Please set environment variables "
+ "OPENVPN_BIN and BITMASK_ROOT pointing to the right path "
+ "to use this command")
+ sys.exit(1)
+
+ bin_paths = OPENVPN_BIN, BITMASK_ROOT
+ if not all(bin_paths):
+ exit()
+
+ if not all(map(os.path.isfile, bin_paths)):
+ exit()
+
+ openvpn_bin_hash, bitmask_root_hash = map(
+ lambda path: hashlib.sha256(open(path).read()).hexdigest(),
+ bin_paths)
+
+ template = r"""
+# Hashes for binaries used in Bitmask Bundle.
+# This file has been automatically generated by `setup.py hash_binaries`
+# DO NOT modify it manually.
+
+OPENVPN_BIN = "{openvpn}"
+BITMASK_ROOT = "{bitmask}"
+"""
+ subst_template = template.format(
+ openvpn=openvpn_bin_hash,
+ bitmask=bitmask_root_hash)
+
+ bin_hash_path = os.path.join('src', 'leap', 'bitmask', '_binaries.py')
+ with open(bin_hash_path, 'w') as f:
+ f.write(subst_template)
+ print("Binaries hash file %s has been updated!" % (bin_hash_path,))
+
+
+cmdclass["hash_binaries"] = cmd_binary_hash
+
+
# next two classes need to augment the versioneer modified ones
versioneer_build = cmdclass['build']