Add code sign on OSX
authorTomás Touceda <chiiph@leap.se>
Fri, 7 Mar 2014 23:22:44 +0000 (20:22 -0300)
committerTomás Touceda <chiiph@leap.se>
Fri, 7 Mar 2014 23:22:44 +0000 (20:22 -0300)
bundler/actions.py
bundler/main.py

index d860548..aee222c 100644 (file)
@@ -14,7 +14,7 @@ from distutils import file_util, dir_util
 from utils import IS_MAC, IS_WIN
 
 if IS_MAC:
-    from sh import SetFile, hdiutil
+    from sh import SetFile, hdiutil, codesign
     from darwin_dyliber import fix_all_dylibs
 if IS_WIN:
     import pbs
@@ -558,7 +558,8 @@ class DmgIt(Action):
         dmg_path = os.path.join(self._basedir, dmg_name)
 
         hdiutil("create", "-srcfolder", dmg_dir, "-volname", vol_name,
-                "-format", "UDRW", "-ov",
+                "-fsargs", "-c c=64,a=16,e=16", "-fs", "HFS+",
+                "-format", "UDRW", "-ov", "-size", "500000k",
                 raw_dmg_path)
         rm("-rf", dmg_dir)
         mkdir(dmg_dir)
@@ -567,7 +568,8 @@ class DmgIt(Action):
         hdiutil("detach", dmg_dir)
 
         rm("-rf", dmg_dir)
-        hdiutil("convert", raw_dmg_path, "-format", "UDZO", "-o",
+        hdiutil("convert", raw_dmg_path, "-format", "UDZO",
+                "-imagekey", "zlib-level=9", "-o",
                 dmg_path)
         rm("-f", raw_dmg_path)
         print "Done"
@@ -647,3 +649,38 @@ class ZipIt(Action):
         self._zipdir(name, zf)
         zf.close()
         print "Done"
+
+
+class SignIt(Action):
+    def __init__(self, basedir, skip, do):
+        Action.__init__(self, "signit", basedir, skip, do)
+
+    @skippable
+    def run(self, identity):
+        print "Signing main structure, this will take a while..."
+        main_app = os.path.join(self._basedir,
+                                "Bitmask",
+                                "Bitmask.app")
+        codesign("-s", identity, "--deep", main_app)
+        print "Done"
+        print "Signing tuntap installer..."
+        tuntap_app = os.path.join(self._basedir,
+                                  "Bitmask",
+                                  "Bitmask.app",
+                                  "Contents",
+                                  "Resources",
+                                  "tuntap-installer.app")
+        codesign("-s", identity, "--deep", tuntap_app)
+        print "Done"
+        print "Signing tuntap kext..."
+        kext = os.path.join(self._basedir,
+                            "Bitmask",
+                            "Bitmask.app",
+                            "Contents",
+                            "Resources",
+                            "tuntap-installer.app",
+                            "Contents",
+                            "Extensions",
+                            "tun.kext")
+        codesign("-s", identity, "--deep", kext)
+        print "Done"
index f3308a6..5590e01 100644 (file)
@@ -13,7 +13,7 @@ from distutils import dir_util
 from actions import GitCloneAll, PythonSetupAll, CreateDirStructure
 from actions import CollectAllDeps, CopyBinaries, PLister, SeededConfig
 from actions import DarwinLauncher, CopyAssets, CopyMisc, FixDylibs
-from actions import DmgIt, PycRemover, TarballIt, MtEmAll, ZipIt
+from actions import DmgIt, PycRemover, TarballIt, MtEmAll, ZipIt, SignIt
 
 from utils import IS_MAC, IS_WIN
 
@@ -28,6 +28,7 @@ sorted_repos = [
     "thandy"
 ]
 
+
 @contextmanager
 def new_build_dir(default=None):
     bd = default
@@ -38,6 +39,7 @@ def new_build_dir(default=None):
     if default is None:
         dir_util.remove_tree(bd)
 
+
 def main():
     parser = argparse.ArgumentParser(description='Bundle creation tool.')
     parser.add_argument('--workon', help="")
@@ -47,6 +49,7 @@ def main():
     parser.add_argument('--binaries', help="")
     parser.add_argument('--seeded-config', help="")
     parser.add_argument('--nightly', action="store_true", help="")
+    parser.add_argument('--codesign', default="", help="")
 
     args = parser.parse_args()
 
@@ -86,10 +89,6 @@ def main():
             cb = init(CopyBinaries)
             cb.run(binaries_path)
 
-        if seeded_config is not None:
-            sc = init(SeededConfig)
-            sc.run(seeded_config)
-
         if IS_MAC:
             pl = init(PLister)
             pl.run()
@@ -111,6 +110,14 @@ def main():
             mt.run()
 
         if IS_MAC:
+            si = init(SignIt)
+            si.run(args.codesign)
+
+        if seeded_config is not None:
+            sc = init(SeededConfig)
+            sc.run(seeded_config)
+
+        if IS_MAC:
             dm = init(DmgIt)
             dm.run(sorted_repos, args.nightly)
         elif IS_WIN: