From 980a84326bf2daa398b201fd3722696476c4913d Mon Sep 17 00:00:00 2001
From: Maximilian Hils <git@maximilianhils.com>
Date: Sun, 11 Dec 2016 23:07:47 +0100
Subject: InstallBuilder (#1826)

---
 release/hooks/hook-cryptography.py             |   3 +-
 release/hooks/hook-pydivert.py                 |   2 +-
 release/installbuilder/.gitignore              |   2 +
 release/installbuilder/license.xml.enc         |   1 +
 release/installbuilder/logo-installer-icon.png | Bin 0 -> 4506 bytes
 release/installbuilder/logo-installer.png      | Bin 0 -> 39467 bytes
 release/installbuilder/logo.ico                | Bin 0 -> 98065 bytes
 release/installbuilder/mitmproxy.xml           | 135 +++++++++++++++++++++++++
 release/rtool.py                               |  52 ++++++++--
 release/setup.py                               |   1 +
 10 files changed, 186 insertions(+), 10 deletions(-)
 create mode 100644 release/installbuilder/.gitignore
 create mode 100644 release/installbuilder/license.xml.enc
 create mode 100644 release/installbuilder/logo-installer-icon.png
 create mode 100644 release/installbuilder/logo-installer.png
 create mode 100644 release/installbuilder/logo.ico
 create mode 100644 release/installbuilder/mitmproxy.xml

(limited to 'release')

diff --git a/release/hooks/hook-cryptography.py b/release/hooks/hook-cryptography.py
index d53a438b..5ecbd6cc 100644
--- a/release/hooks/hook-cryptography.py
+++ b/release/hooks/hook-cryptography.py
@@ -1,4 +1,5 @@
 # Taken from the latest pyinstaller master on 2016-11-27 (0729a2b).
+# flake8: noqa
 
 #-----------------------------------------------------------------------------
 # Copyright (c) 2005-2016, PyInstaller Development Team.
@@ -40,4 +41,4 @@ cryptography_dir = os.path.dirname(get_module_file_attribute('cryptography'))
 for ext in EXTENSION_SUFFIXES:
     ffimods = glob.glob(os.path.join(cryptography_dir, '*_cffi_*%s*' % ext))
     for f in ffimods:
-        binaries.append((f, 'cryptography'))
\ No newline at end of file
+        binaries.append((f, 'cryptography'))
diff --git a/release/hooks/hook-pydivert.py b/release/hooks/hook-pydivert.py
index 3fe8c552..72b7eb7d 100644
--- a/release/hooks/hook-pydivert.py
+++ b/release/hooks/hook-pydivert.py
@@ -1,3 +1,3 @@
 from PyInstaller.utils.hooks import collect_data_files
 
-datas = collect_data_files('pydivert.windivert_dll')
\ No newline at end of file
+datas = collect_data_files('pydivert.windivert_dll')
diff --git a/release/installbuilder/.gitignore b/release/installbuilder/.gitignore
new file mode 100644
index 00000000..00c10a2d
--- /dev/null
+++ b/release/installbuilder/.gitignore
@@ -0,0 +1,2 @@
+license.xml
+*.xml.backup
\ No newline at end of file
diff --git a/release/installbuilder/license.xml.enc b/release/installbuilder/license.xml.enc
new file mode 100644
index 00000000..3df7210a
--- /dev/null
+++ b/release/installbuilder/license.xml.enc
@@ -0,0 +1 @@
+gAAAAABYSXtgysddnqWL5sAreDTENJZdFkEf9p2nfMZTynY2hEep8vIDwR0P1glL40C04kLUv3piHkqyz0I893b-_YpnZC-W7qwfhChoFxnAQd0NY_d1mLsCHF1nQK0k907IbextZ3XHSCqSkS2nw0S41p9sEbzWLludSRRqJRn-AmxAKdm5s43kheNpP5iArWKtBrtubgytIDanulTfibdAPHaZedyx3JDww3hIUgo2shird7L4q2xQsE0bBDBgGrlndZ6lYGJDKf600LpOPSzSON6uXdPefhPD1bZP0GAFTNMAkm0K39e9J-j9Xz5ao7bEswfR6pcYO1uQC9VmxJYdLkuY9vYiltED6m5dW--NXVx0pudr_e5BXfpT5-RdUHaGM0Od6EZggeD5PNgUtWXxmXd6C0gFBZZEx_KobDXrCD9s8tmRJjb3ACBSCh2NdfFCCfOU3JRHeSgANTDYzY0pcJicoE5UcvP2dEICVvEORwbTumtfWbuDSbXwHqcynVjkJbwxHhRMMeJtjnx4dbb6_wdp2RjOUilTb2ob40OWyU0szgpSe2-5XS_F7ixL7vMf00OHFtTDk0Wg_dv15IR3C-zK8WFWEr4b4POc1P6pRrKOLKIFIKBGGZWF-S-u3gedAL2VLpFoUCG5FMnnJGv2iNfNYkG20zObn9K6FG5uNq6T0ZvfJIjJYNvXV45mx7jhOg2R5HAkZXlx16iIv95qlHIvJR6UZKHqWr_Hp3YvaxatkqbFwpXxQU0xtMJO3dXafATFMW_l
\ No newline at end of file
diff --git a/release/installbuilder/logo-installer-icon.png b/release/installbuilder/logo-installer-icon.png
new file mode 100644
index 00000000..c39541bb
Binary files /dev/null and b/release/installbuilder/logo-installer-icon.png differ
diff --git a/release/installbuilder/logo-installer.png b/release/installbuilder/logo-installer.png
new file mode 100644
index 00000000..42de543d
Binary files /dev/null and b/release/installbuilder/logo-installer.png differ
diff --git a/release/installbuilder/logo.ico b/release/installbuilder/logo.ico
new file mode 100644
index 00000000..8e08e8cc
Binary files /dev/null and b/release/installbuilder/logo.ico differ
diff --git a/release/installbuilder/mitmproxy.xml b/release/installbuilder/mitmproxy.xml
new file mode 100644
index 00000000..e4ad00a3
--- /dev/null
+++ b/release/installbuilder/mitmproxy.xml
@@ -0,0 +1,135 @@
+<project>
+    <shortName>mitmproxy</shortName>
+    <fullName>mitmproxy</fullName>
+    <version>1.0</version>
+    <leftImage>logo-installer.png</leftImage>
+    <logoImage>logo-installer-icon.png</logoImage>
+    <componentList>
+        <component>
+            <name>default</name>
+            <description>Default Component</description>
+            <canBeEdited>1</canBeEdited>
+            <selected>1</selected>
+            <show>1</show>
+            <folderList>
+                <folder>
+                    <description>Program Files</description>
+                    <destination>${installdir}</destination>
+                    <name>programfiles</name>
+                    <platforms>all</platforms>
+                    <distributionFileList>
+                        <distributionFile>
+                            <origin>logo.ico</origin>
+                        </distributionFile>
+                    </distributionFileList>
+                </folder>
+                <folder>
+                    <description>Program Files/bin</description>
+                    <destination>${installdir}/bin</destination>
+                    <name>binaries</name>
+                    <platforms>all</platforms>
+                    <distributionFileList>
+                        <distributionFile>
+                            <allowWildcards>1</allowWildcards>
+                            <excludeFiles>*/patho*</excludeFiles>
+                            <origin>../build/binaries/${platform_name}/*</origin>
+                        </distributionFile>
+                    </distributionFileList>
+                </folder>
+            </folderList>
+            <postInstallationActionList>
+                <addDirectoryToPath>
+                    <insertAt>end</insertAt>
+                    <path>${installdir}/bin</path>
+                    <scope>user</scope>
+                </addDirectoryToPath>
+            </postInstallationActionList>
+            <postUninstallationActionList>
+                <removeDirectoryFromPath>
+                    <path>${installdir}/bin</path>
+                    <scope>user</scope>
+                </removeDirectoryFromPath>
+            </postUninstallationActionList>
+            <startMenuShortcutList>
+                <startMenuShortcut>
+                    <comment></comment>
+                    <name>mitmproxy ui</name>
+                    <runAsAdmin>0</runAsAdmin>
+                    <runInTerminal>0</runInTerminal>
+                    <windowsExec>${installdir}\bin\mitmweb.exe</windowsExec>
+                    <windowsExecArgs></windowsExecArgs>
+                    <windowsIcon>${installdir}/logo.ico</windowsIcon>
+                    <windowsPath>${installdir}</windowsPath>
+                </startMenuShortcut>
+                <startMenuShortcut>
+                    <comment></comment>
+                    <name>mitmdump</name>
+                    <runAsAdmin>0</runAsAdmin>
+                    <runInTerminal>0</runInTerminal>
+                    <windowsExec>${installdir}\bin\mitmdump.exe</windowsExec>
+                    <windowsExecArgs></windowsExecArgs>
+                    <windowsIcon>${installdir}/logo.ico</windowsIcon>
+                    <windowsPath>${installdir}</windowsPath>
+                </startMenuShortcut>
+            </startMenuShortcutList>
+        </component>
+    </componentList>
+    <createOsxBundleDmg>1</createOsxBundleDmg>
+    <disableSplashScreen>1</disableSplashScreen>
+    <enableRollback>1</enableRollback>
+    <enableTimestamp>1</enableTimestamp>
+    <outputDirectory>../dist</outputDirectory>
+    <productDisplayIcon>logo.ico</productDisplayIcon>
+    <saveRelativePaths>1</saveRelativePaths>
+    <vendor>mitmproxy.org</vendor>
+    <windowsExecutableIcon>logo.ico</windowsExecutableIcon>
+    <finalPageActionList>
+        <runProgram>
+            <program>cmd</program>
+            <programArguments>/c start "mitmproxy ui" "${installdir}\bin\mitmweb.exe" &amp;</programArguments>
+            <progressText>Launch mitmproxy ui now</progressText>
+            <ruleList>
+                <platformTest>
+                    <type>windows</type>
+                </platformTest>
+            </ruleList>
+        </runProgram>
+        <runProgram>
+            <program>${installdir}/mitmproxy</program>
+            <programArguments>&amp;</programArguments>
+            <progressText>Launch mitmproxy now</progressText>
+            <ruleList>
+                <platformTest>
+                    <negate>1</negate>
+                    <type>windows</type>
+                </platformTest>
+            </ruleList>
+        </runProgram>
+    </finalPageActionList>
+    <parameterList>
+        <directoryParameter>
+            <name>installdir</name>
+            <description>Installer.Parameter.installdir.description</description>
+            <explanation>Installer.Parameter.installdir.explanation</explanation>
+            <value></value>
+            <default>${platform_install_prefix}/${product_shortname}</default>
+            <allowEmptyValue>0</allowEmptyValue>
+            <ask>yes</ask>
+            <cliOptionName>prefix</cliOptionName>
+            <mustBeWritable>yes</mustBeWritable>
+            <mustExist>0</mustExist>
+            <width>40</width>
+            <postShowPageActionList>
+                <!-- This will skip the readytoinstall page -->
+                <setInstallerVariable name="next_page" value="installation"/>
+            </postShowPageActionList>
+            <preShowPageActionList>
+                <setInstallerVariable>
+                    <name>ui.button(next).text</name>
+                    <value>${msg(Installer.Button.Install)}</value>
+                </setInstallerVariable>
+            </preShowPageActionList>
+        </directoryParameter>
+    </parameterList>
+</project>
+
diff --git a/release/rtool.py b/release/rtool.py
index 4a6d1e16..59899510 100755
--- a/release/rtool.py
+++ b/release/rtool.py
@@ -13,6 +13,7 @@ import zipfile
 from os.path import join, abspath, dirname, exists, basename
 
 import click
+import cryptography.fernet
 import pysftp
 
 # https://virtualenv.pypa.io/en/latest/userguide.html#windows-notes
@@ -37,6 +38,12 @@ else:
     def Archive(name):
         return tarfile.open(name, "w:gz")
 
+PLATFORM_TAG = {
+    "Darwin": "osx",
+    "Windows": "windows",
+    "Linux": "linux",
+}.get(platform.system(), platform.system())
+
 ROOT_DIR = abspath(join(dirname(__file__), ".."))
 RELEASE_DIR = join(ROOT_DIR, "release")
 
@@ -47,7 +54,7 @@ PYINSTALLER_SPEC = join(RELEASE_DIR, "specs")
 # PyInstaller 3.2 does not bundle pydivert's Windivert binaries
 PYINSTALLER_HOOKS = join(RELEASE_DIR, "hooks")
 PYINSTALLER_TEMP = join(BUILD_DIR, "pyinstaller")
-PYINSTALLER_DIST = join(BUILD_DIR, "binaries")
+PYINSTALLER_DIST = join(BUILD_DIR, "binaries", PLATFORM_TAG)
 
 VENV_DIR = join(BUILD_DIR, "venv")
 
@@ -91,11 +98,6 @@ def get_snapshot_version() -> str:
 
 
 def archive_name(bdist: str) -> str:
-    platform_tag = {
-        "Darwin": "osx",
-        "Windows": "win32",
-        "Linux": "linux"
-    }.get(platform.system(), platform.system())
     if platform.system() == "Windows":
         ext = "zip"
     else:
@@ -103,7 +105,7 @@ def archive_name(bdist: str) -> str:
     return "{project}-{version}-{platform}.{ext}".format(
         project=bdist,
         version=get_version(),
-        platform=platform_tag,
+        platform=PLATFORM_TAG,
         ext=ext
     )
 
@@ -114,6 +116,19 @@ def wheel_name() -> str:
     )
 
 
+def installer_name() -> str:
+    ext = {
+        "Windows": "exe",
+        "Darwin": "dmg",
+        "Linux": "run"
+    }[platform.system()]
+    return "mitmproxy-{version}-{platform}-installer.{ext}".format(
+        version=get_version(),
+        platform=PLATFORM_TAG,
+        ext=ext,
+    )
+
+
 @contextlib.contextmanager
 def chdir(path: str):
     old_dir = os.getcwd()
@@ -130,6 +145,24 @@ def cli():
     pass
 
 
+@cli.command("encrypt")
+@click.argument('infile', type=click.File('rb'))
+@click.argument('outfile', type=click.File('wb'))
+@click.argument('key', envvar='RTOOL_KEY')
+def encrypt(infile, outfile, key):
+    f = cryptography.fernet.Fernet(key.encode())
+    outfile.write(f.encrypt(infile.read()))
+
+
+@cli.command("decrypt")
+@click.argument('infile', type=click.File('rb'))
+@click.argument('outfile', type=click.File('wb'))
+@click.argument('key', envvar='RTOOL_KEY')
+def decrypt(infile, outfile, key):
+    f = cryptography.fernet.Fernet(key.encode())
+    outfile.write(f.decrypt(infile.read()))
+
+
 @cli.command("contributors")
 def contributors():
     """
@@ -238,7 +271,8 @@ def upload_release(username, password, repository):
 @click.option("--private-key-password", envvar="SNAPSHOT_PASS", prompt=True, hide_input=True)
 @click.option("--wheel/--no-wheel", default=False)
 @click.option("--bdist/--no-bdist", default=False)
-def upload_snapshot(host, port, user, private_key, private_key_password, wheel, bdist):
+@click.option("--installer/--no-installer", default=False)
+def upload_snapshot(host, port, user, private_key, private_key_password, wheel, bdist, installer):
     """
     Upload snapshot to snapshot server
     """
@@ -256,6 +290,8 @@ def upload_snapshot(host, port, user, private_key, private_key_password, wheel,
             if bdist:
                 for bdist in sorted(BDISTS.keys()):
                     files.append(archive_name(bdist))
+            if installer:
+                files.append(installer_name())
 
             for f in files:
                 local_path = join(DIST_DIR, f)
diff --git a/release/setup.py b/release/setup.py
index 1d60e46c..01d0672d 100644
--- a/release/setup.py
+++ b/release/setup.py
@@ -8,6 +8,7 @@ setup(
         "click>=6.2, <7.0",
         "twine>=1.6.5, <1.9",
         "pysftp==0.2.8",
+        "cryptography>=1.6, <1.7",
     ],
     entry_points={
         "console_scripts": [
-- 
cgit v1.2.3