From ef892643df8970aec45dbc3f48eabb95a1ccbf22 Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 30 Sep 2020 16:25:27 +0200 Subject: [pkg] osx helper and working qt installer --- branding/templates/qtinstaller/config/config.xml | 22 +++++ branding/templates/qtinstaller/installer.pro | 36 ++++++++ branding/templates/qtinstaller/osx/post-install.py | 98 ++++++++++++++++++++++ .../qtinstaller/osx/se.leap.bitmask-helper.plist | 26 ++++++ .../qtinstaller/packages/bitmaskvpn/.gitignore | 1 + .../packages/bitmaskvpn/meta/install.js | 53 ++++++++++++ .../packages/bitmaskvpn/meta/package.xml | 11 +++ 7 files changed, 247 insertions(+) create mode 100644 branding/templates/qtinstaller/config/config.xml create mode 100644 branding/templates/qtinstaller/installer.pro create mode 100755 branding/templates/qtinstaller/osx/post-install.py create mode 100644 branding/templates/qtinstaller/osx/se.leap.bitmask-helper.plist create mode 100644 branding/templates/qtinstaller/packages/bitmaskvpn/.gitignore create mode 100644 branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js create mode 100644 branding/templates/qtinstaller/packages/bitmaskvpn/meta/package.xml (limited to 'branding/templates/qtinstaller') diff --git a/branding/templates/qtinstaller/config/config.xml b/branding/templates/qtinstaller/config/config.xml new file mode 100644 index 0000000..936726d --- /dev/null +++ b/branding/templates/qtinstaller/config/config.xml @@ -0,0 +1,22 @@ + + + DemoLibVPN-0.0.1 + 0.0.1 + DemoLibVPN Installer + LEAP Encryption Access Project + @ApplicationsDir@/DemoLibVPN + @TargetDir@/demolib-vpn.app + + + DemoLibVPN + false + + Uninstall-DemoLibVPN + mac + diff --git a/branding/templates/qtinstaller/installer.pro b/branding/templates/qtinstaller/installer.pro new file mode 100644 index 0000000..ec800c1 --- /dev/null +++ b/branding/templates/qtinstaller/installer.pro @@ -0,0 +1,36 @@ +!defined(INSTALLER, var):INSTALLER= "BitmaskVPN-Installer-git" +TEMPLATE = aux +CONFIG -= debug_and_release + +INPUT = $$PWD/config/config.xml $$PWD/packages +inst.input = INPUT +inst.output = $$INSTALLER +inst.commands = binarycreator -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT} +inst.CONFIG += target_predeps no_link combine + +QMAKE_EXTRA_COMPILERS += inst + +OTHER_FILES += \ +# watch out... it chokes with dashes in the path + packages/riseupvpn/meta/package.xml \ + packages/riseupvpn/meta/install.js \ + packages/riseupvpn/data/README.txt \ + +macx { + OTHER_FILES += "packages/riseupvpn/data/riseup-vpn.app" + OTHER_FILES += "packages/riseupvpn/data/bitmask-helper" + OTHER_FILES += "packages/riseupvpn/data/installer.py" + OTHER_FILES += "packages/riseupvpn/data/se.leap.bitmask-helper.plist" + OTHER_FILES += "packages/riseupvpn/data/openvpn.leap" + OTHER_FILES += "packages/riseupvpn/data/helper/bitmask.pf.conf" + OTHER_FILES += "packages/riseupvpn/data/client.up.sh" + OTHER_FILES += "packages/riseupvpn/data/client.down.sh" +} +linux { + OTHER_FILES += "packages/riseupvpn/data/riseup-vpn" + OTHER_FILES += "packages/riseupvpn/data/bitmask-helper" +} +win32{ + OTHER_FILES += "packages/riseupvpn/data/riseup-vpn.exe" + OTHER_FILES += "packages/riseupvpn/data/helper.exe" +} diff --git a/branding/templates/qtinstaller/osx/post-install.py b/branding/templates/qtinstaller/osx/post-install.py new file mode 100755 index 0000000..32b4780 --- /dev/null +++ b/branding/templates/qtinstaller/osx/post-install.py @@ -0,0 +1,98 @@ +#!/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(): + log = open(os.path.join(_dir, 'post-install.log'), 'w') + 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, err) + + # failure: sys.exit(1) + + 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)) + + ok = fixHelperOwner(log) + log.write("chown helper: %s \n" % str(ok)) + + log.write("Copy launch daemon...\n") + copyLaunchDaemon() + + log.write("Trying to launch helper...\n") + out = launchHelper() + log.write("result: %s \n" % str(out)) + + grantPermissionsOnLogFolder() + + # all done + 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]) + out2 = subprocess.call(["pkill", "-9", "bitmask-helper"]) # just in case + 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(): + 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(): + out = subprocess.call(["launchctl", "load", "/Library/LaunchDaemons/se.leap.bitmask-helper.plist"]) + return out == 0 + +def grantPermissionsOnLogFolder(): + helperDir = os.path.join(_dir, 'helper') + try: + os.makedirs(helperDir) + except Exception: + pass + os.chown(helperDir, 0, 0) + +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() diff --git a/branding/templates/qtinstaller/osx/se.leap.bitmask-helper.plist b/branding/templates/qtinstaller/osx/se.leap.bitmask-helper.plist new file mode 100644 index 0000000..c9d9687 --- /dev/null +++ b/branding/templates/qtinstaller/osx/se.leap.bitmask-helper.plist @@ -0,0 +1,26 @@ + + + + + WorkingDirectory + /tmp + StandardOutPath + bitmask-helper.log + StandardErrorPath + bitmask-helper-err.log + GroupName + daemon + RunAtLoad + + SessionCreate + + KeepAlive + + ThrottleInterval + 5 + Label + se.leap.BitmaskHelper + Program + PATH/bitmask-helper + + diff --git a/branding/templates/qtinstaller/packages/bitmaskvpn/.gitignore b/branding/templates/qtinstaller/packages/bitmaskvpn/.gitignore new file mode 100644 index 0000000..60baa9c --- /dev/null +++ b/branding/templates/qtinstaller/packages/bitmaskvpn/.gitignore @@ -0,0 +1 @@ +data/* diff --git a/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js b/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js new file mode 100644 index 0000000..f9c85f2 --- /dev/null +++ b/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2020 LEAP +** +****************************************************************************/ + +function Component() { +} + +Component.prototype.createOperations = function () +{ + // This will actually install the files + component.createOperations(); + + // And now our custom actions. + // See https://doc.qt.io/qtinstallerframework/operations.html for reference + // + // We can also use this to register different components (different architecture for instance) + // See https://doc.qt.io/qtinstallerframework/qt-installer-framework-systeminfo-packages-root-meta-installscript-qs.html + + if (systemInfo.productType === "windows") { + postInstallWindows(); + } else if (systemInfo.productType === "osx") { + postInstallOSX(); + } else { + postInstallLinux(); + } +} + +function postInstallWindows() { + component.addOperation( + "CreateShortcut", + "@TargetDir@/README.txt", + "@StartMenuDir@/README.lnk", + "workingDirectory=@TargetDir@", + "iconPath=%SystemRoot%/system32/SHELL32.dll", + "iconId=2"); +} + +function postInstallOSX() { + console.log("Post-installation for OSX"); + // TODO add UNDOEXECUTE for the uninstaller + component.addElevatedOperation( + "Execute", "{0}", + "@TargetDir@/post-install.py", + "errormessage=There was an error during the post-installation script, things might be broken. Please report this error and attach the post-install.log file."); +} + +function postInstallLinux() { + console.log("Post-installation for GNU/Linux"); + console.log("Maybe you want to use your package manager instead?"); + component.addOperation("AppendFile", "/tmp/riseupvpn.log", "this is a test - written from the installer"); +} diff --git a/branding/templates/qtinstaller/packages/bitmaskvpn/meta/package.xml b/branding/templates/qtinstaller/packages/bitmaskvpn/meta/package.xml new file mode 100644 index 0000000..b910e7f --- /dev/null +++ b/branding/templates/qtinstaller/packages/bitmaskvpn/meta/package.xml @@ -0,0 +1,11 @@ + + + DemoLibVPN + DemoLibVPN + 0.20.9-1 + 2020-10-01 + false + true + + true + -- cgit v1.2.3