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 | |
parent | c77ba97502da5c954447abf738ab78108d1b0892 (diff) |
[pkg] parametrize win/osx installer
Diffstat (limited to 'branding')
14 files changed, 191 insertions, 134 deletions
diff --git a/branding/qtinstaller/config/config.xml b/branding/qtinstaller/config/config.xml deleted file mode 100644 index 8ce9b2e..0000000 --- a/branding/qtinstaller/config/config.xml +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<Installer> - <Name>DemoLibVPN-0.0.1</Name> - <Version>0.0.1</Version> - <Title>DemoLibVPN Installer</Title> - <Publisher>LEAP Encryption Access Project</Publisher> - <TargetDir>@ApplicationsDir@/DemoLibVPN</TargetDir> - <RunProgram>@TargetDir@/demolib-vpn.exe</RunProgram> - <RunProgramArguments> - </RunProgramArguments> - <StartMenuDir>DemoLibVPN</StartMenuDir> - <MaintenanceToolName>Uninstall-DemoLibVPN</MaintenanceToolName> - <AllowNonAsciiCharacters>false</AllowNonAsciiCharacters> -</Installer> diff --git a/branding/qtinstaller/packages/root.win_x86_64/.gitignore b/branding/qtinstaller/packages/root.win_x86_64/.gitignore deleted file mode 100644 index 60baa9c..0000000 --- a/branding/qtinstaller/packages/root.win_x86_64/.gitignore +++ /dev/null @@ -1 +0,0 @@ -data/* diff --git a/branding/qtinstaller/packages/root.win_x86_64/meta/installscript.js b/branding/qtinstaller/packages/root.win_x86_64/meta/installscript.js deleted file mode 100644 index 1598458..0000000 --- a/branding/qtinstaller/packages/root.win_x86_64/meta/installscript.js +++ /dev/null @@ -1,77 +0,0 @@ -/* -** -** Copyright (C) 2020 LEAP Encryption Access Project. -** -*/ - -function cancelInstaller(message) -{ - installer.setDefaultPageVisible(QInstaller.Introduction, false); - installer.setDefaultPageVisible(QInstaller.TargetDirectory, false); - installer.setDefaultPageVisible(QInstaller.ComponentSelection, false); - installer.setDefaultPageVisible(QInstaller.ReadyForInstallation, false); - installer.setDefaultPageVisible(QInstaller.StartMenuSelection, false); - installer.setDefaultPageVisible(QInstaller.PerformInstallation, false); - installer.setDefaultPageVisible(QInstaller.LicenseCheck, false); - - var abortText = "<font color='red'>" + message +"</font>"; - installer.setValue("FinishedText", abortText); -} -function majorVersion(str) -{ - return parseInt(str.split(".", 1)); -} - -function Component() -{ - // Check whether OS is supported. - // start installer with -v to see debug output - - console.log("OS: " + systemInfo.productType); - console.log("Kernel: " + systemInfo.kernelType + "/" + systemInfo.kernelVersion); - - var validOs = false; - - if (systemInfo.kernelType === "winnt") { - if (majorVersion(systemInfo.kernelVersion) >= 6) - validOs = true; - } else if (systemInfo.kernelType === "darwin") { - if (majorVersion(systemInfo.kernelVersion) >= 11) - validOs = true; - } else { - if (systemInfo.productType !== "ubuntu" - || systemInfo.productVersion !== "20.04") { - QMessageBox["warning"]("os.warning", "Installer", - "Note that the binaries are only tested on Ubuntu 20.04", - QMessageBox.Ok); - } - validOs = true; - } - - if (!validOs) { - cancelInstaller("Installation on " + systemInfo.prettyProductName + " is not supported"); - return; - } - - console.log("CPU Architecture: " + systemInfo.currentCpuArchitecture); - - if ( systemInfo.kernelType === "winnt") { - installer.componentByName("root.win_x86_64").setValue("Default", "true"); - installer.componentByName("root.win_x86_64").setValue("Virtual", "false"); - } -} - -Component.prototype.createOperations = function() -{ - component.createOperations() - component.addElevatedOperation("Execute", "@TargetDir@/helper.exe", "install", "UNDOEXECUTE", "@TargetDir@/helper.exe", "remove"); - component.addElevatedOperation("Execute", "@TargetDir@/helper.exe", "start", "UNDOEXECUTE", "@TargetDir@/helper.exe", "stop"); - if (systemInfo.productType === "windows") { - console.log("Adding shortcut entries"); - component.addElevatedOperation("Mkdir", "@StartMenuDir@"); - component.addElevatedOperation("CreateShortcut", "@TargetDir@/demolib-vpn.exe", "@StartMenuDir@/DemoLibVPN.lnk", "workingDirectory=@TargetDir@", "iconPath=@TargetDir@/icon.ico", "description=Start DemoLibVPN"); - - // TODO I think this one is not being created because the path doesn't exist yet. We might want to do this by hooking on the installation finished signal instead. - component.addElevatedOperation("CreateShortcut", "@TargetDir@/Uninstall-DemoLibVPN.exe", "@StartMenuDir@/Uninstall.lnk"); - } -} diff --git a/branding/qtinstaller/packages/root.win_x86_64/meta/package.xml b/branding/qtinstaller/packages/root.win_x86_64/meta/package.xml deleted file mode 100644 index 11d630f..0000000 --- a/branding/qtinstaller/packages/root.win_x86_64/meta/package.xml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<Package> - <DisplayName>DemoLibVPN For Windows</DisplayName> - <Description>Install DemoLibVPN</Description> - <Version>0.0.1-1</Version> - <ReleaseDate>2020-09-15</ReleaseDate> - <Default>true</Default> - <RequiresAdminRights>true</RequiresAdminRights> - <Script>installscript.js</Script> -</Package> diff --git a/branding/qtinstaller/packages/root/meta/package.xml b/branding/qtinstaller/packages/root/meta/package.xml deleted file mode 100644 index b4ca25e..0000000 --- a/branding/qtinstaller/packages/root/meta/package.xml +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<Package> - <DisplayName>DemoLibVPN</DisplayName> - <Version>0.0.1-1</Version> - <ReleaseDate>2020-09-15</ReleaseDate> - <Default>script</Default> -</Package> 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) diff --git a/branding/templates/qtinstaller/config/config.xml b/branding/templates/qtinstaller/config/config.xml index 8b28be6..c02b0a6 100644 --- a/branding/templates/qtinstaller/config/config.xml +++ b/branding/templates/qtinstaller/config/config.xml @@ -1,13 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <Installer> - - <Name>DemoLibVPN-0.0.1</Name> - <Version>0.0.1</Version> - <Title>DemoLibVPN Installer</Title> + <Name>$APPNAME-$VERSION</Name> + <Version>$VERSION</Version> + <Title>$APPNAME Installer ($VERSION)</Title> <Publisher>LEAP Encryption Access Project</Publisher> - <TargetDir>@ApplicationsDir@/DemoLibVPN.app</TargetDir> - - <StartMenuDir>DemoLibVPN.app</StartMenuDir> <AllowNonAsciiCharacters>false</AllowNonAsciiCharacters> <!-- @@ -18,15 +14,8 @@ </RemoteRepositories> --> - <MaintenanceToolName>Uninstall-DemoLibVPN</MaintenanceToolName> + <MaintenanceToolName>Uninstall-$APPNAME</MaintenanceToolName> - <!-- osx run --> - <RunProgram>open</RunProgram> - <RunProgramDescription>Start DemoLibVPN now!</RunProgramDescription> - <RunProgramArguments> - <Argument>@TargetDir@</Argument> - </RunProgramArguments> - <WizardStyle>mac</WizardStyle> - <!-- end osx run --> + $PLATFORM_BLOCK </Installer> diff --git a/branding/templates/qtinstaller/linux-data/readme b/branding/templates/qtinstaller/linux-data/readme new file mode 100644 index 0000000..e039088 --- /dev/null +++ b/branding/templates/qtinstaller/linux-data/readme @@ -0,0 +1 @@ +linux-specific installer data diff --git a/branding/templates/qtinstaller/osx/post-install.py b/branding/templates/qtinstaller/osx-data/post-install.py index 2c15845..2c15845 100755 --- a/branding/templates/qtinstaller/osx/post-install.py +++ b/branding/templates/qtinstaller/osx-data/post-install.py diff --git a/branding/templates/qtinstaller/osx/se.leap.bitmask-helper.plist b/branding/templates/qtinstaller/osx-data/se.leap.bitmask-helper.plist index c333aba..c333aba 100644 --- a/branding/templates/qtinstaller/osx/se.leap.bitmask-helper.plist +++ b/branding/templates/qtinstaller/osx-data/se.leap.bitmask-helper.plist diff --git a/branding/templates/qtinstaller/osx/uninstall.py b/branding/templates/qtinstaller/osx-data/uninstall.py index 7aa8a56..7aa8a56 100755 --- a/branding/templates/qtinstaller/osx/uninstall.py +++ b/branding/templates/qtinstaller/osx-data/uninstall.py diff --git a/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js b/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js index 0bcaeef..361e14d 100644 --- a/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js +++ b/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js @@ -1,10 +1,64 @@ /**************************************************************************** ** -** Copyright (C) 2020 LEAP +** Copyright (C) 2020 LEAP Encryption Access Project ** ****************************************************************************/ +function majorVersion(str) +{ + return parseInt(str.split(".", 1)); +} + +function cancelInstaller(message) +{ + installer.setDefaultPageVisible(QInstaller.Introduction, false); + installer.setDefaultPageVisible(QInstaller.TargetDirectory, false); + installer.setDefaultPageVisible(QInstaller.ComponentSelection, false); + installer.setDefaultPageVisible(QInstaller.ReadyForInstallation, false); + installer.setDefaultPageVisible(QInstaller.StartMenuSelection, false); + installer.setDefaultPageVisible(QInstaller.PerformInstallation, false); + installer.setDefaultPageVisible(QInstaller.LicenseCheck, false); + + var abortText = "<font color='red'>" + message +"</font>"; + installer.setValue("FinishedText", abortText); +} + function Component() { + // Check whether OS is supported. + // start installer with -v to see debug output + + console.log("OS: " + systemInfo.productType); + console.log("Kernel: " + systemInfo.kernelType + "/" + systemInfo.kernelVersion); + + var validOs = false; + + if (systemInfo.kernelType === "winnt") { + if (majorVersion(systemInfo.kernelVersion) >= 6) + validOs = true; + } else if (systemInfo.kernelType === "darwin") { + if (majorVersion(systemInfo.kernelVersion) >= 11) + validOs = true; + } else { + if (systemInfo.productType !== "ubuntu" + || systemInfo.productVersion !== "20.04") { + QMessageBox["warning"]("os.warning", "Installer", + "Note that the binaries are only tested on Ubuntu 20.04", + QMessageBox.Ok); + } + validOs = true; + } + + if (!validOs) { + cancelInstaller("Installation on " + systemInfo.prettyProductName + " is not supported"); + return; + } + + console.log("CPU Architecture: " + systemInfo.currentCpuArchitecture); + + if ( systemInfo.kernelType === "winnt") { + installer.componentByName("root.win_x86_64").setValue("Default", "true"); + installer.componentByName("root.win_x86_64").setValue("Virtual", "false"); + } } Component.prototype.createOperations = function () @@ -31,7 +85,7 @@ Component.prototype.installationFinished = function() { console.log("DEBUG: running installationFinished"); if (installer.isInstaller() && installer.status == QInstaller.Success) { - var argList = ["-a", "@TargetDir@/DemoLibVPN.app"]; + var argList = ["-a", "@TargetDir@/$APPNAME.app"]; try { installer.execute("touch", ["/tmp/install-finished"]); installer.execute("open", argList); @@ -46,12 +100,12 @@ function postInstallWindows() { component.addElevatedOperation("Execute", "@TargetDir@/helper.exe", "start", "UNDOEXECUTE", "@TargetDir@/helper.exe", "stop"); console.log("Adding shortcut entries"); component.addElevatedOperation("Mkdir", "@StartMenuDir@"); - component.addElevatedOperation("CreateShortcut", "@TargetDir@/demolib-vpn.exe", "@StartMenuDir@/DemoLibVPN.lnk", "workingDirectory=@TargetDir@", "iconPath=@TargetDir@/icon.ico", "description=Start DemoLibVPN"); + component.addElevatedOperation("CreateShortcut", "@TargetDir@/$BINNAME.exe", "@StartMenuDir@/$APPNAME.lnk", "workingDirectory=@TargetDir@", "iconPath=@TargetDir@/icon.ico", "description=Start $APPNAME"); // TODO I think this one is not being created because the path doesn't exist yet. We might want to do this by hooking on the installation finished signal instead. component.addElevatedOperation( "CreateShortcut", - "@TargetDir@/Uninstall-DemoLibVPN.exe", + "@TargetDir@/Uninstall-$APPNAME.exe", "@StartMenuDir@/Uninstall.lnk" ); } @@ -70,5 +124,5 @@ function postInstallOSX() { 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"); + component.addOperation("AppendFile", "/tmp/bitmask-installer.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 index b910e7f..0e56f4f 100644 --- a/branding/templates/qtinstaller/packages/bitmaskvpn/meta/package.xml +++ b/branding/templates/qtinstaller/packages/bitmaskvpn/meta/package.xml @@ -1,9 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <Package> - <DisplayName>DemoLibVPN</DisplayName> - <Description>DemoLibVPN</Description> - <Version>0.20.9-1</Version> - <ReleaseDate>2020-10-01</ReleaseDate> + <DisplayName>$APPNAME</DisplayName> + <Description>$APPNAME</Description> + <Version>$VERSION</Version> + <ReleaseDate>$TIMESTAMP</ReleaseDate> <Default>false</Default> <RequiresAdminRights>true</RequiresAdminRights> <Script>install.js</Script> diff --git a/branding/templates/qtinstaller/win-data/readme b/branding/templates/qtinstaller/win-data/readme new file mode 100644 index 0000000..8938b54 --- /dev/null +++ b/branding/templates/qtinstaller/win-data/readme @@ -0,0 +1 @@ +windows-specific installer data |