diff options
Diffstat (limited to 'branding/templates/qtinstaller/osx')
-rwxr-xr-x | branding/templates/qtinstaller/osx/post-install.py | 6 | ||||
-rwxr-xr-x | branding/templates/qtinstaller/osx/uninstall.py | 70 |
2 files changed, 73 insertions, 3 deletions
diff --git a/branding/templates/qtinstaller/osx/post-install.py b/branding/templates/qtinstaller/osx/post-install.py index 18059aa..2c15845 100755 --- a/branding/templates/qtinstaller/osx/post-install.py +++ b/branding/templates/qtinstaller/osx/post-install.py @@ -12,6 +12,7 @@ import subprocess HELPER = "bitmask-helper" HELPER_PLIST = "/Library/LaunchDaemons/se.leap.bitmask-helper.plist" + _dir = os.path.dirname(os.path.realpath(__file__)) def main(): @@ -73,13 +74,12 @@ def fixHelperOwner(log): def copyLaunchDaemon(): 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) + shutil.copy(path, HELPER_PLIST) def launchHelper(): - out = subprocess.call(["launchctl", "load", "/Library/LaunchDaemons/se.leap.bitmask-helper.plist"]) + out = subprocess.call(["launchctl", "load", HELPER_PLIST]) return out == 0 def grantPermissionsOnLogFolder(): diff --git a/branding/templates/qtinstaller/osx/uninstall.py b/branding/templates/qtinstaller/osx/uninstall.py new file mode 100755 index 0000000..7aa8a56 --- /dev/null +++ b/branding/templates/qtinstaller/osx/uninstall.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python + +# Uninstall script for BitmaskVPN. + +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(): + log = open(os.path.join('/tmp', 'bitmask-uninstall.log'), 'w') + log.write('Checking for admin privileges...\n') + + _id = os.getuid() + log.write("UID: %s\n" % str(_id)) + if int(_id) != 0: + err = "error: need to run as root. UID: %s\n" % str(_id) + logErr(log, err) + + # failure: sys.exit(1) + + log.write('Checking if helper is running') + + if isHelperRunning(): + 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)) + + log.write("Removing LaunchDaemon") + out = removeLaunchDaemon() + log.write("result: %s \n" % str(out)) + + # all done + log.write('uninstall script: done\n') + sys.exit(0) + + +def logErr(log, msg): + log.write(msg) + sys.exit(1) + +def isHelperRunning(): + ps = _getProcessList() + return HELPER in ps + +def unloadHelper(): + out = subprocess.call(["launchctl", "unload", HELPER_PLIST]) + out2 = subprocess.call(["pkill", "-9", "bitmask-helper"]) # just in case + return out == 0 + +def removeLaunchDaemon(): + return subprocess.call(["rm", "-f", HELPER_PLIST]) + +def _getProcessList(): + _out = [] + output = subprocess.Popen(["ps", "-ceA"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + stdout, stderr = output.communicate() + for line in stdout.split('\n'): + cmd = line.split(' ')[-1] + _out.append(cmd.strip()) + return _out + +if __name__ == "__main__": + main() |