diff options
Diffstat (limited to 'installer/packages/riseupvpn/data/post-install.py')
-rwxr-xr-x | installer/packages/riseupvpn/data/post-install.py | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/installer/packages/riseupvpn/data/post-install.py b/installer/packages/riseupvpn/data/post-install.py index 1e1addd..02da859 100755 --- a/installer/packages/riseupvpn/data/post-install.py +++ b/installer/packages/riseupvpn/data/post-install.py @@ -1,49 +1,49 @@ #!/usr/bin/env python import os +import shutil import sys import subprocess HELPER = "bitmask-helper" HELPER_PLIST = "/Library/LaunchDaemons/se.leap.bitmask-helper.plist" +_dir = os.path.dirname(os.path.realpath(__file__)) def main(): - _dir = os.path.dirname(os.path.realpath(__file__)) log = open(os.path.join(_dir, 'post-install.log'), 'w') - log.write('Checking for admin privileges...') + log.write('Checking for admin privileges...\n') _id = os.getuid() if _id != 0: err = "error: need to run as root. UID: %s\n" % str(_id) - logErr(log, msg) + logErr(log, err) # failure: sys.exit(1) if isHelperRunning(): - log.write("Trying to stop bitmask-helper...") + log.write("Trying to stop bitmask-helper...\n") # if this fail, we can check if the HELPER_PLIST is there ok = unloadHelper() log.write("success: %s \n" % str(ok)) - ok = makeHelperExecutable() - log.write("chmod +x helper: %s \n" % str(ok)) + ok = fixHelperOwner(log) + log.write("chown helper: %s \n" % str(ok)) - # 3. cp se.leap.bitmask-helper.plist /Library/LaunchDaemons/ + log.write("Copy launch daemon...\n") copyLaunchDaemon() - # 4. launchctl load /Library/LaunchDaemons/se.leap.bitmask-helper.plist - launchHelper() + out = launchHelper() + log.write("Copy plist: %s \n" % str(ok)) - # 5. chown admin:wheel /Applications/$applicationName.app/Contents/helper # is this the folder? grantPermissionsOnLogFolder() - # all good - log.write('post-install script: done') + # all done + log.write('post-install script: done\n') sys.exit(0) def logErr(log, msg): - log.write(err) + log.write(msg) sys.exit(1) def isHelperRunning(): @@ -54,18 +54,34 @@ def unloadHelper(): out = subprocess.call(["launchctl", "unload", HELPER_PLIST]) return out == 0 -def makeHelperExecutable(): - out = subprocess.call(["chmod", "+x", HELPER]) - return out == 0 +def fixHelperOwner(log): + path = os.path.join(_dir, HELPER) + try: + os.chown(path, 0, 0) + except OSError as exc: + log.write(str(exc)) + return False + return True def copyLaunchDaemon(): - pass + plist = "se.leap.bitmask-helper.plist" + path = os.path.join(_dir, plist) + dest = os.path.join('/Library/LaunchDaemons', plist) + _p = _dir.replace("/", "\/") + subprocess.call(["sed", "-i.back", "s/PATH/%s/" % _p, path]) + shutil.copy(path, dest) def launchHelper(): - pass + out = subprocess.call(["launchctl", "load", "/Library/LaunchDaemons/se.leap.bitmask-helper.plist"]) + return out == 0 def grantPermissionsOnLogFolder(): - pass + helperDir = os.path.join(_dir, 'helper') + try: + os.makedirs(helperDir) + except Exception: + pass + os.chown(helperDir, 0, 0) def _getProcessList(): _out = [] |