summaryrefslogtreecommitdiff
path: root/osx/generate.py
diff options
context:
space:
mode:
Diffstat (limited to 'osx/generate.py')
-rw-r--r--osx/generate.py84
1 files changed, 69 insertions, 15 deletions
diff --git a/osx/generate.py b/osx/generate.py
index 57aa11e..b8a6bec 100644
--- a/osx/generate.py
+++ b/osx/generate.py
@@ -9,50 +9,104 @@ import stat
from string import Template
# Variables ----------------------------
-# TODO consolidate version string for all builds.
-VERSION = "0.0.1"
APP_NAME = "RiseupVPN"
BUNDLE_IDENTIFIER = "se.leap.riseupvpn"
+
# Do not edit below --------------------
-TEMPLATE = 'template-info.plist'
+here = os.path.split(os.path.abspath(__file__))[0]
+
ENTRYPOINT = 'bitmask-systray'
HELPER = 'bitmask_helper'
+TEMPLATE_INFO = 'template-info.plist'
+TEMPLATE_HELPER = 'template-helper.plist'
+TEMPLATE_PREINSTALL = 'template-preinstall'
+TEMPLATE_POSTINSTALL = 'template-postinstall'
+VERSION = open(os.path.join(here, '..', 'version')).read().strip()
-here = os.path.split(os.path.abspath(__file__))[0]
APP_PATH = os.path.abspath(here + '/../dist/' + APP_NAME + ".app")
STAGING = os.path.abspath(here + '/../staging/')
+ASSETS = os.path.abspath(here + '/../assets/')
+ICON = os.path.join(ASSETS, APP_NAME.lower() + '.icns')
+SCRIPTS = os.path.join(os.path.abspath(here), 'scripts')
+INFO_PLIST = APP_PATH + '/Contents/Info.plist'
+HELPER_PLIST = os.path.join(SCRIPTS, 'se.leap.bitmask-helper.plist')
+PREINSTALL = os.path.join(SCRIPTS, 'preinstall')
+POSTINSTALL = os.path.join(SCRIPTS, 'postinstall')
os.makedirs(APP_PATH + "/Contents/MacOS", exist_ok=True)
-
-INFO_PLIST = APP_PATH + '/Contents/Info.plist'
+os.makedirs(APP_PATH + "/Contents/Resources", exist_ok=True)
+os.makedirs(APP_PATH + "/Contents/helper", exist_ok=True)
vardict = {
'entrypoint': ENTRYPOINT,
'info_string': APP_NAME + " " + VERSION,
'bundle_identifier': BUNDLE_IDENTIFIER,
'bundle_name': APP_NAME,
- 'version': VERSION
+ 'version': VERSION,
+ 'app_name': APP_NAME
}
-template = Template(open(TEMPLATE).read())
-with open(INFO_PLIST, 'w') as output:
- output.write(template.safe_substitute(vardict))
+# utils
+
+def copy_payload(filename):
+ destfile = APP_PATH + "/Contents/MacOS/" + filename
+ shutil.copyfile(STAGING + '/' + filename, destfile)
+ cmode = os.stat(destfile).st_mode
+ os.chmod(destfile, cmode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
+
+def generate_from_template(template, dest, vardict):
+ print("[+] File written from template to", dest)
+ template = Template(open(template).read())
+ with open(dest, 'w') as output:
+ output.write(template.safe_substitute(vardict))
+
+# 1. Generation of the Bundle Info.plist
+# --------------------------------------
+generate_from_template(TEMPLATE_INFO, INFO_PLIST, vardict)
+
+
+# 2. Generate PkgInfo
+# -------------------------------------------
+# XXX is this enough?
f = open(APP_PATH + "/Contents/PkgInfo", "w")
f.write("APPL????")
f.close()
-def copy_payload(filename):
- destfile = APP_PATH + "/Contents/MacOS/" + filename
- shutil.copyfile(STAGING + '/' + filename, destfile)
- cmode = os.stat(destfile).st_mode
- os.chmod(destfile, cmode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
+# 3. Copy the binary payloads
+# --------------------------------------------
copy_payload(ENTRYPOINT)
copy_payload(HELPER)
+# 4. Copy the app icon
+# -----------------------------------------------
+shutil.copyfile(ICON, APP_PATH + '/Contents/Resources/app.icns')
+
+
+# 5. Generate the scripts for the installer
+# -----------------------------------------------
+generate_from_template(TEMPLATE_HELPER, HELPER_PLIST, vardict)
+generate_from_template(TEMPLATE_PREINSTALL, PREINSTALL, vardict)
+generate_from_template(TEMPLATE_POSTINSTALL, POSTINSTALL, vardict)
+
+
+# 6. Generate uninstall script
+# -----------------------------------------------
+# TODO copy the uninstaller script from bitmask-dev
+# TODO substitute vars
+# TODO this is a bit weak for now.
+# To begin with, this assumes everything is hardcoded into /Applications/APPNAME.app
+# We could consider moving the helpers into /usr/local/sbin, so that the plist files
+# always reference there.
+
+
+# We're all set here.
+print("[+] Output written to dist/{appname}.app".format(appname=APP_NAME))
+
+