diff options
Diffstat (limited to 'branding/templates/qtinstaller/osx-data/uninstall.py')
-rwxr-xr-x | branding/templates/qtinstaller/osx-data/uninstall.py | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/branding/templates/qtinstaller/osx-data/uninstall.py b/branding/templates/qtinstaller/osx-data/uninstall.py index d47acc5..ef012e4 100755 --- a/branding/templates/qtinstaller/osx-data/uninstall.py +++ b/branding/templates/qtinstaller/osx-data/uninstall.py @@ -6,6 +6,7 @@ import os import shutil import sys import subprocess +import time HELPER = "bitmask-helper" HELPER_PLIST = "/Library/LaunchDaemons/se.leap.bitmask-helper.plist" @@ -21,16 +22,19 @@ def main(stage="uninstall"): 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(err) + sys.exit(1) log.write('Checking if helper is running\n') if isHelperRunning(): log.write("Trying to stop bitmask-helper...\n") # if this fail, we can check if the HELPER_PLIST is there - ok = unloadHelper() + try: + ok = unloadHelper() + except Exception as exc: + log.write('error: %v' % exc) + time.sleep(0.5) log.write("success: %s \n" % str(ok)) log.write("Removing LaunchDaemon\n") @@ -41,14 +45,14 @@ def main(stage="uninstall"): log.write(stage + ' script: done\n') sys.exit(0) - -def logErr(log, msg): - log.write(msg) - sys.exit(1) - def isHelperRunning(): - ps = _getProcessList() - return HELPER in ps + try: + pid = subprocess.check_output(['pgrep', HELPER]) + if pid.strip() != '': + return True + except subprocess.CalledProcessError: + return False + return False def unloadHelper(): out = subprocess.call(["launchctl", "unload", HELPER_PLIST]) @@ -58,17 +62,8 @@ def unloadHelper(): 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__": stage="uninstall" - if len(sys.argv) > 2 and sys.argv[2] == "pre": - stage="pre-install" + if len(sys.argv) == 2 and sys.argv[1] == "pre": + stage="preinstall" main(stage) |