From 1ae11e5c615c996cbef3db694fc571bfe6524d1d Mon Sep 17 00:00:00 2001
From: "kali kaneko (leap communications)" <kali@leap.se>
Date: Wed, 8 Jul 2020 20:43:12 +0200
Subject: [PATCH] [pkg] boilerplate for qtinstaller framework

---
 Makefile                                      |  3 ++
 bitmask.pro                                   |  1 +
 gui/build.sh                                  |  4 +-
 gui/handlers.h                                |  2 -
 installer/.gitignore                          |  4 ++
 installer/bitmask-installer.pro               | 21 ++++++++
 installer/config/config.xml                   | 12 +++++
 installer/packages/riseupvpn/data/README.txt  |  1 +
 installer/packages/riseupvpn/meta/install.js  | 51 +++++++++++++++++++
 installer/packages/riseupvpn/meta/package.xml | 11 ++++
 10 files changed, 106 insertions(+), 4 deletions(-)
 create mode 100644 installer/.gitignore
 create mode 100644 installer/bitmask-installer.pro
 create mode 100644 installer/config/config.xml
 create mode 100644 installer/packages/riseupvpn/data/README.txt
 create mode 100644 installer/packages/riseupvpn/meta/install.js
 create mode 100644 installer/packages/riseupvpn/meta/package.xml

diff --git a/Makefile b/Makefile
index 78f2e933..a62f2e20 100644
--- a/Makefile
+++ b/Makefile
@@ -58,6 +58,9 @@ dependsCygwin:
 	@choco install -y golang python nssm nsis wget 7zip
 
 build:
+	gui/build.sh
+
+build_old:
 ifeq (${XBUILD}, yes)
 	$(MAKE) build_cross_win
 	$(MAKE) build_cross_osx
diff --git a/bitmask.pro b/bitmask.pro
index 3ab85079..7f4b488a 100644
--- a/bitmask.pro
+++ b/bitmask.pro
@@ -9,6 +9,7 @@ QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.14
 
 macx {
     LIBS += -framework Security
+    ICON = ./branding/assets/riseup/icon.icns
 }
 
 QT += qml quick widgets
diff --git a/gui/build.sh b/gui/build.sh
index 1ded17ed..91be4fcd 100755
--- a/gui/build.sh
+++ b/gui/build.sh
@@ -20,8 +20,8 @@ fi
 if [ "$XBUILD" == "$WIN64" ]
 then
     # TODO allow to override vars
-    QMAKE="`pwd`/../mxe/usr/x86_64-w64-mingw32.static/qt5/bin/qmake"
-    PATH="`pwd`/../mxe/usr/bin"/:$PATH
+    QMAKE="`pwd`/../../mxe/usr/x86_64-w64-mingw32.static/qt5/bin/qmake"
+    PATH="`pwd`/../../mxe/usr/bin"/:$PATH
     CC=x86_64-w64-mingw32.static-gcc
 else
     if [ "$QMAKE" == "" ]
diff --git a/gui/handlers.h b/gui/handlers.h
index d746524b..c342a977 100644
--- a/gui/handlers.h
+++ b/gui/handlers.h
@@ -12,8 +12,6 @@ class QJsonWatch : public QObject {
 
     Q_OBJECT
 
-    QJsonModel *model;
-
 public:
 
 signals:
diff --git a/installer/.gitignore b/installer/.gitignore
new file mode 100644
index 00000000..2fdd01e5
--- /dev/null
+++ b/installer/.gitignore
@@ -0,0 +1,4 @@
+.qmake.stash
+Makefile
+packages/riseupvpn/data/riseup-vpn
+RiseupVPN-Installer
diff --git a/installer/bitmask-installer.pro b/installer/bitmask-installer.pro
new file mode 100644
index 00000000..c526283d
--- /dev/null
+++ b/installer/bitmask-installer.pro
@@ -0,0 +1,21 @@
+TEMPLATE = aux
+
+CONFIG -= debug_and_release
+
+INSTALLER = RiseupVPN-Installer
+
+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 \
+    packages/riseupvpn/data/riseup-vpn
+
diff --git a/installer/config/config.xml b/installer/config/config.xml
new file mode 100644
index 00000000..ef0e5e8b
--- /dev/null
+++ b/installer/config/config.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Installer>
+    <Name>RiseupVPN Installer 1.0</Name>
+    <Title>RiseupVPN Installer</Title>
+    <Version>1.0.0</Version>
+    <TargetDir>@ApplicationsDir@/RiseupVPN</TargetDir>
+    <RemoteRepositories>
+        <Repository>
+            <Url>http://localhost/repository/</Url>
+        </Repository>
+    </RemoteRepositories>
+</Installer>
diff --git a/installer/packages/riseupvpn/data/README.txt b/installer/packages/riseupvpn/data/README.txt
new file mode 100644
index 00000000..616eb29e
--- /dev/null
+++ b/installer/packages/riseupvpn/data/README.txt
@@ -0,0 +1 @@
+RiseupVPN README
diff --git a/installer/packages/riseupvpn/meta/install.js b/installer/packages/riseupvpn/meta/install.js
new file mode 100644
index 00000000..e5174e17
--- /dev/null
+++ b/installer/packages/riseupvpn/meta/install.js
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** 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
+
+    console.log("Post installation. Checking platform...")
+    if (systemInfo.productType === "windows") {
+        console.log("Platform: windows");
+        postInstallWindows();
+    } else if (systemInfo.productType === "osx") {
+        console.log("Platform: osx");
+        postInstallOSX();
+    } else {
+        console.log("Platform: linux");
+        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("TODO: should do osx post-installation");
+}
+
+function postInstallLinux() {
+    console.log("TODO: should do linux post-installation");
+    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/installer/packages/riseupvpn/meta/package.xml b/installer/packages/riseupvpn/meta/package.xml
new file mode 100644
index 00000000..4dd7ae9e
--- /dev/null
+++ b/installer/packages/riseupvpn/meta/package.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Package>
+    <DisplayName>RiseupVPN</DisplayName>
+    <Description>RiseupVPN</Description>
+    <Version>0.20.6-1</Version>
+    <ReleaseDate>2020-07-01</ReleaseDate>
+    <Default>false</Default>
+    <RequiresAdminRights>true</RequiresAdminRights>
+    <Script>install.js</Script>
+    <ForcedInstallation>true</ForcedInstallation>
+</Package>
-- 
GitLab