summaryrefslogtreecommitdiff
path: root/branding/templates/qtinstaller/osx-data/uninstall.py
blob: ef012e4d2528a8a010388ca6b37bcce6e501b485 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python

# Uninstall script for BitmaskVPN.

import os
import shutil
import sys
import subprocess
import time

HELPER = "bitmask-helper"
HELPER_PLIST = "/Library/LaunchDaemons/se.leap.bitmask-helper.plist"

_dir = os.path.dirname(os.path.realpath(__file__))

def main(stage="uninstall"):
    logfile = "bitmask-{stage}.log".format(stage=stage)
    log = open(os.path.join('/tmp', logfile), '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)
      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
        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")
    out = removeLaunchDaemon()
    log.write("result: %s \n" % str(out))
    
    # all done
    log.write(stage + ' script: done\n')
    sys.exit(0)

def isHelperRunning():
    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])
    out2 = subprocess.call(["pkill", "-9", "bitmask-helper"])  # just in case
    return out == 0

def removeLaunchDaemon():
    return subprocess.call(["rm", "-f", HELPER_PLIST])

if __name__ == "__main__":
    stage="uninstall"
    if len(sys.argv) == 2 and sys.argv[1] == "pre":
        stage="preinstall"
    main(stage)