summaryrefslogtreecommitdiff
path: root/branding/templates/qtinstaller/osx-data
diff options
context:
space:
mode:
authorkali <kali@leap.se>2021-02-19 12:20:55 +0100
committerkali kaneko (leap communications) <kali@leap.se>2021-02-26 22:40:44 +0100
commit4a4b6b46f84c28640c711655f4f3c339ccf8fbba (patch)
treefd17ca92a5366251133b400866e8a5e97891712f /branding/templates/qtinstaller/osx-data
parent51308ecd42d4c8d7724a8eaf517294fd9d369cf0 (diff)
[pkg] improve osx installer
- install into global /Applications - document how to troubleshoot helper - uninstall app is visible on top-level folder - improve detection of running processes for old and new binaries - Closes: #441 - Closes: #445 - Closes: #435
Diffstat (limited to 'branding/templates/qtinstaller/osx-data')
-rwxr-xr-xbranding/templates/qtinstaller/osx-data/post-install.py26
-rwxr-xr-xbranding/templates/qtinstaller/osx-data/uninstall.py39
2 files changed, 30 insertions, 35 deletions
diff --git a/branding/templates/qtinstaller/osx-data/post-install.py b/branding/templates/qtinstaller/osx-data/post-install.py
index 2c15845..83c8370 100755
--- a/branding/templates/qtinstaller/osx-data/post-install.py
+++ b/branding/templates/qtinstaller/osx-data/post-install.py
@@ -5,15 +5,18 @@
# This means that, for the time being, you can only install ONE of the BitmaskVPN derivatives at the same time.
# This might change in the future.
+import glob
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__))
+_appdir = glob.glob('{}/*VPN.app'.format(_dir))[0]
def main():
log = open(os.path.join(_dir, 'post-install.log'), 'w')
@@ -21,10 +24,9 @@ def main():
_id = os.getuid()
if _id != 0:
- err = "error: need to run as root. UID: %s\n" % str(_id)
- logErr(log, err)
-
- # failure: sys.exit(1)
+ err = "ERROR: need to run as root. UID: %s\n" % str(_id)
+ log.write(err)
+ sys.exit(1)
if isHelperRunning():
log.write("Trying to stop bitmask-helper...\n")
@@ -48,22 +50,19 @@ def main():
log.write('post-install 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])
+ time.sleep(0.5)
out2 = subprocess.call(["pkill", "-9", "bitmask-helper"]) # just in case
+ time.sleep(0.5)
return out == 0
def fixHelperOwner(log):
- path = os.path.join(_dir, HELPER)
+ path = os.path.join(_appdir, HELPER)
try:
os.chown(path, 0, 0)
except OSError as exc:
@@ -74,8 +73,9 @@ def fixHelperOwner(log):
def copyLaunchDaemon():
plist = "se.leap.bitmask-helper.plist"
path = os.path.join(_dir, plist)
- _p = _dir.replace("/", "\/")
- subprocess.call(["sed", "-i.back", "s/PATH/%s/" % _p, path])
+ _p = os.path.join(_dir, _appdir)
+ _p2= _p.replace("/", "\/")
+ subprocess.call(["sed", "-i.back", "s/PATH/%s/" % _p2, path])
shutil.copy(path, HELPER_PLIST)
def launchHelper():
@@ -83,7 +83,7 @@ def launchHelper():
return out == 0
def grantPermissionsOnLogFolder():
- helperDir = os.path.join(_dir, 'helper')
+ helperDir = os.path.join(_appdir, 'helper')
try:
os.makedirs(helperDir)
except Exception:
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)