From 4d9d578902aae37d62ea3218efa2b062cb7f893f Mon Sep 17 00:00:00 2001 From: kali Date: Thu, 8 Oct 2020 03:04:25 +0200 Subject: [pkg] parametrize win/osx installer --- branding/scripts/gen-qtinstaller | 121 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100755 branding/scripts/gen-qtinstaller (limited to 'branding/scripts') diff --git a/branding/scripts/gen-qtinstaller b/branding/scripts/gen-qtinstaller new file mode 100755 index 0000000..419d958 --- /dev/null +++ b/branding/scripts/gen-qtinstaller @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 + +import configparser +import json +import os +import sys +import time + +from string import Template + +from provider import getDefaultProvider +from provider import getProviderData + +OS_CONFIG = { + 'osx': """ + + @ApplicationsDir@/$APPNAME.app + $APPNAME.app + open + Start $APPNAME now! + + @TargetDir@ + + mac + +""", + 'windows': """ + @ApplicationsDir@/DemoLibVPN + $APPNAME + + @TargetDir@/$BINNAME.exe + + + +""" +} + + + +def getData(): + config = configparser.ConfigParser() + configPath = os.path.join(here(), '../../branding/config/vendor.conf') + config.read(configPath) + + provider = os.environ.get('PROVIDER') + if not provider: + provider = getDefaultProvider(config) + return getProviderData(provider, config) + +def generateQtInstallerBoilerplate(data, platform, outDir): + generateConfig(data, platform, outDir) + generatePackageMetadata(data, platform, outDir) + +def generateConfig(data, platform, outDir): + templateData = { + 'APPNAME': data['applicationName'], + 'BINNAME': data['binaryName'], + 'VERSION': getVersion(), + 'TIMESTAMP': time.strftime('%Y-%m-%d'), + } + + platformStr = OS_CONFIG[platform] + platBlock = Template(platformStr).substitute(**templateData) + templateData['PLATFORM_BLOCK'] = platBlock + + renderTemplate( + templatePath='../templates/qtinstaller/config/config.xml', + outPath=os.path.join(outDir, 'config/config.xml'), + data=templateData) + +def generatePackageMetadata(data, platform, outDir): + templateData = { + 'APPNAME': data['applicationName'], + 'BINNAME': data['binaryName'], + 'VERSION': getVersion(), + 'TIMESTAMP': time.strftime('%Y-%m-%d') + } + renderTemplate( + templatePath='../templates/qtinstaller/packages/bitmaskvpn/meta/package.xml', + outPath=os.path.join(outDir, 'packages/bitmaskvpn/meta/package.xml'), + data=templateData) + + renderTemplate( + templatePath='../templates/qtinstaller/packages/bitmaskvpn/meta/install.js', + outPath=os.path.join(outDir, 'packages/bitmaskvpn/meta/install.js'), + data=templateData) + +def renderTemplate(templatePath=None, outPath=None, data=None): + with open(os.path.join(here(), templatePath), 'r') as f: + t = f.read() + rendered = Template(t).substitute(**data) + os.makedirs(os.path.dirname(outPath), exist_ok=True) + with open(outPath, 'w') as out: + out.write(rendered) + +def here(): + return os.path.abspath(os.path.dirname(__file__)) + +def bail(msg=None): + if not msg: + print("ERROR: not enough arguments!") + print('Usage: {scriptname}.py '.format( + scriptname=SCRIPT_NAME)) + else: + print(msg) + sys.exit(1) + +def getVersion(): + return os.environ.get('VERSION', 'unknown') + +if __name__ == "__main__": + # TODO get from vendor - maybe just in provider module + VENDOR_PATH = os.environ.get('VENDOR_PATH') + + if len(sys.argv) != 3: + bail() + platform = sys.argv[1] + outDir = sys.argv[2] + print("[+] Generating qtinstaller files...") + data = getData() + generateQtInstallerBoilerplate(data, platform, outDir) -- cgit v1.2.3