diff options
author | kali <kali@leap.se> | 2020-10-08 03:04:25 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2020-10-13 19:08:50 +0200 |
commit | 4d9d578902aae37d62ea3218efa2b062cb7f893f (patch) | |
tree | 39c96fc5d3cb7703e2fbea07e5782fcdb4b4189a /branding/scripts | |
parent | c77ba97502da5c954447abf738ab78108d1b0892 (diff) |
[pkg] parametrize win/osx installer
Diffstat (limited to 'branding/scripts')
-rwxr-xr-x | branding/scripts/gen-qtinstaller | 121 |
1 files changed, 121 insertions, 0 deletions
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': """ + <!-- osx --> + <TargetDir>@ApplicationsDir@/$APPNAME.app</TargetDir> + <StartMenuDir>$APPNAME.app</StartMenuDir> + <RunProgram>open</RunProgram> + <RunProgramDescription>Start $APPNAME now!</RunProgramDescription> + <RunProgramArguments> + <Argument>@TargetDir@</Argument> + </RunProgramArguments> + <WizardStyle>mac</WizardStyle> + <!-- end osx --> +""", + 'windows': """ + <TargetDir>@ApplicationsDir@/DemoLibVPN</TargetDir> + <StartMenuDir>$APPNAME</StartMenuDir> + + <RunProgram>@TargetDir@/$BINNAME.exe</RunProgram> + <RunProgramArguments> + </RunProgramArguments> + <!-- end windows --> +""" +} + + + +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 <config> <output>'.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) |