From 5d102497e80f17056ce97bcc58a4906cf8a05c28 Mon Sep 17 00:00:00 2001 From: kali Date: Fri, 25 Sep 2020 17:46:50 +0200 Subject: [bug] workaround for helper path in windows --- Makefile | 11 ++-- branding/qtinstaller/config/config.xml | 9 ++- .../packages/root.win_x86_64/meta/installscript.js | 6 +- build.sh | 72 ---------------------- docs/build.windows.rst | 9 +++ gui/build.sh | 72 ++++++++++++++++++++++ pkg/helper/helper.go | 4 +- pkg/helper/windows.go | 18 ++++-- 8 files changed, 114 insertions(+), 87 deletions(-) delete mode 100755 build.sh create mode 100644 docs/build.windows.rst create mode 100644 gui/build.sh diff --git a/Makefile b/Makefile index e1af715..000b755 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ XBUILD ?= no SKIP_CACHECK ?= no PROVIDER ?= $(shell grep ^'provider =' branding/config/vendor.conf | cut -d '=' -f 2 | tr -d "[:space:]") +TARGET ?= bitmask PROVIDER_CONFIG ?= branding/config/vendor.conf DEFAULT_PROVIDER = branding/assets/default/ VERSION ?= $(shell git describe) @@ -20,11 +21,12 @@ SOURCE_GOLIB=gui/backend.go # detect OS, we use it for dependencies UNAME = $(shell uname -s) PLATFORM ?= $(shell echo ${UNAME} | awk "{print tolower(\$$0)}") +WININST_DATA = branding/qtinstaller/packages/root.win_x86_64/data/ TEMPLATES = branding/templates SCRIPTS = branding/scripts -all: icon locales build +all: icon locales helper build ######################################################################### @@ -66,7 +68,7 @@ else ifeq (${XBUILD}, osx) $(MAKE) build_cross_osx $(MAKE) _build_done else - $(MAKE) _buildparts + @gui/build.sh endif @@ -224,8 +226,9 @@ package_deb: @make -C build/${PROVIDER} pkg_deb installer_win: - cp qtbuild/release/bitmask.exe branding/qtinstaller/packages/root.win_x86_64/data/${PROVIDER}-vpn.exe - windeployqt --qmldir gui/qml branding/qtinstaller/packages/root.win_x86_64/data/${PROVIDER}-vpn.exe + cp helper.exe ${WININST_DATA} + cp qtbuild/release/${TARGET}.exe ${WININST_DATA}${PROVIDER}-vpn.exe + windeployqt --qmldir gui/qml ${WININST_DATA}${PROVIDER}-vpn.exe "/c/Qt/QtIFW-3.2.2/bin/binarycreator.exe" -c ./branding/qtinstaller/config/config.xml -p ./branding/qtinstaller/packages build/${PROVIDER}-vpn-${VERSION}-installer.exe # FIXME --- old nsis installer. deprecate, but probably we need something similar to sign all the binaries (helper, main app, installer...) diff --git a/branding/qtinstaller/config/config.xml b/branding/qtinstaller/config/config.xml index 4469d65..8ce9b2e 100644 --- a/branding/qtinstaller/config/config.xml +++ b/branding/qtinstaller/config/config.xml @@ -1,9 +1,14 @@ - DemoLibVPN + DemoLibVPN-0.0.1 0.0.1 DemoLibVPN Installer LEAP Encryption Access Project - DemoLibVPN @ApplicationsDir@/DemoLibVPN + @TargetDir@/demolib-vpn.exe + + + DemoLibVPN + Uninstall-DemoLibVPN + false diff --git a/branding/qtinstaller/packages/root.win_x86_64/meta/installscript.js b/branding/qtinstaller/packages/root.win_x86_64/meta/installscript.js index 691d1a4..1598458 100644 --- a/branding/qtinstaller/packages/root.win_x86_64/meta/installscript.js +++ b/branding/qtinstaller/packages/root.win_x86_64/meta/installscript.js @@ -69,7 +69,9 @@ Component.prototype.createOperations = function() 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=%SystemRoot%/system32/SHELL32.dll", "iconId=2", "description=Start DemoLibVPN"); - component.addElevatedOperation("CreateShortcut", "@TargetDir@/maintenancetool.exe", "@StartMenuDir@/uninstall.lnk", "workingDirectory=@TargetDir@", "iconPath=%SystemRoot%/system32/SHELL32.dll", "iconId=2", "description=Uninstall application"); + 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/build.sh b/build.sh deleted file mode 100755 index 1ded17e..0000000 --- a/build.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash -set -e - - -XBUILD=${XBUILD-no} -WIN64="win64" -GO=`which go` - -PROJECT=bitmask.pro -TARGET_GOLIB=lib/libgoshim.a -SOURCE_GOLIB=gui/backend.go - -RELEASE=qtbuild/release - -if [ "$TARGET" == "" ] -then - TARGET=riseup-vpn -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 - CC=x86_64-w64-mingw32.static-gcc -else - if [ "$QMAKE" == "" ] - then - QMAKE=`which qmake` - fi -fi - - -function init { - mkdir -p lib -} - -function buildGoLib { - echo "[+] Using go in" $GO "[`go version`]" - $GO generate ./pkg/config/version/genver/gen.go - if [ "$XBUILD" == "no" ] - then - echo "[+] Building Go library with standard Go compiler" - CGO_ENABLED=1 go build -buildmode=c-archive -o $TARGET_GOLIB $SOURCE_GOLIB - fi - if [ "$XBUILD" == "$WIN64" ] - then - echo "[+] Building Go library with mxe" - echo "[+] Using cc:" $CC - CC=$CC CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -buildmode=c-archive -o $TARGET_GOLIB $SOURCE_GOLIB - fi -} - -function buildQmake { - echo "[+] Now building Qml app with Qt qmake" - echo "[+] Using qmake in:" $QMAKE - mkdir -p qtbuild - $QMAKE -o qtbuild/Makefile "CONFIG-=debug CONFIG+=release" $PROJECT -} - -echo "[+] Building BitmaskVPN" - -lrelease bitmask.pro -buildGoLib -buildQmake -make -C qtbuild clean -make -C qtbuild -j4 all - -# i would expect that passing QMAKE_TARGET would produce the right output, but nope. -mv qtbuild/release/bitmask $RELEASE/$TARGET -strip $RELEASE/$TARGET -echo "[+] Binary is in" $RELEASE/$TARGET diff --git a/docs/build.windows.rst b/docs/build.windows.rst new file mode 100644 index 0000000..a0c7a56 --- /dev/null +++ b/docs/build.windows.rst @@ -0,0 +1,9 @@ +windows build notes (still some manual steps needed, this should be further automated). +======================================================================================= + +PROVIDER=DemoLib make helper +INSTALLER_DATA=branding/qtinstaller/packages/root.win_x86_64/data/ +mkdir -p INSTALLER_DATA +mv main.exe ${INSTALLER_DATA}/helper.exe +TARGET=demolib-vpn make build +TARGET=demolib-vpn make installer_win diff --git a/gui/build.sh b/gui/build.sh new file mode 100644 index 0000000..1ded17e --- /dev/null +++ b/gui/build.sh @@ -0,0 +1,72 @@ +#!/bin/bash +set -e + + +XBUILD=${XBUILD-no} +WIN64="win64" +GO=`which go` + +PROJECT=bitmask.pro +TARGET_GOLIB=lib/libgoshim.a +SOURCE_GOLIB=gui/backend.go + +RELEASE=qtbuild/release + +if [ "$TARGET" == "" ] +then + TARGET=riseup-vpn +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 + CC=x86_64-w64-mingw32.static-gcc +else + if [ "$QMAKE" == "" ] + then + QMAKE=`which qmake` + fi +fi + + +function init { + mkdir -p lib +} + +function buildGoLib { + echo "[+] Using go in" $GO "[`go version`]" + $GO generate ./pkg/config/version/genver/gen.go + if [ "$XBUILD" == "no" ] + then + echo "[+] Building Go library with standard Go compiler" + CGO_ENABLED=1 go build -buildmode=c-archive -o $TARGET_GOLIB $SOURCE_GOLIB + fi + if [ "$XBUILD" == "$WIN64" ] + then + echo "[+] Building Go library with mxe" + echo "[+] Using cc:" $CC + CC=$CC CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -buildmode=c-archive -o $TARGET_GOLIB $SOURCE_GOLIB + fi +} + +function buildQmake { + echo "[+] Now building Qml app with Qt qmake" + echo "[+] Using qmake in:" $QMAKE + mkdir -p qtbuild + $QMAKE -o qtbuild/Makefile "CONFIG-=debug CONFIG+=release" $PROJECT +} + +echo "[+] Building BitmaskVPN" + +lrelease bitmask.pro +buildGoLib +buildQmake +make -C qtbuild clean +make -C qtbuild -j4 all + +# i would expect that passing QMAKE_TARGET would produce the right output, but nope. +mv qtbuild/release/bitmask $RELEASE/$TARGET +strip $RELEASE/$TARGET +echo "[+] Binary is in" $RELEASE/$TARGET diff --git a/pkg/helper/helper.go b/pkg/helper/helper.go index 9d0b330..691fc6e 100644 --- a/pkg/helper/helper.go +++ b/pkg/helper/helper.go @@ -29,9 +29,9 @@ import ( ) var ( - AppName = "DemoLibVPN" + AppName = "DemoLibVPN" BinaryName = "bitmask" - Version = "git" + Version = "git" ) type openvpnT struct { diff --git a/pkg/helper/windows.go b/pkg/helper/windows.go index ef4f271..44ac6f5 100644 --- a/pkg/helper/windows.go +++ b/pkg/helper/windows.go @@ -33,8 +33,10 @@ import ( var ( svcName = BinaryName + `-helper-v2` + + // XXX this is set to c:\WINDOWS\system32 on initialization. Do not use it, use a function call instead. appPath = getExecDir() - LogFolder = appPath + LogFolder = getExecDir() openvpnPath = path.Join(appPath, "openvpn.exe") chocoOpenvpnPath = `C:\Program Files\OpenVPN\bin\openvpn.exe` platformOpenvpnFlags = []string{ @@ -47,9 +49,11 @@ var ( func getExecDir() string { ex, err := os.Executable() if err != nil { - log.Fatal("Cannot find executable path") + log.Println("Cannot find executable path") + return "" } - return path.Dir(ex) + /* XXX filepath.Abs is buggy, maybe because of spaces in the path. fuck it, this is good enough for now */ + return strings.Replace(ex, "\\helper.exe", "", 1) } type httpConf struct { @@ -131,11 +135,15 @@ func daemonize() {} func runServer(port int) {} func getOpenvpnPath() string { - if _, err := os.Stat(openvpnPath); !os.IsNotExist(err) { - return openvpnPath + openvpn := path.Join(getExecDir(), "openvpn.exe") + if _, err := os.Stat(openvpn); !os.IsNotExist(err) { + log.Println("DEBUG: openvpnpath found,", openvpnPath) + return openvpn } else if _, err := os.Stat(chocoOpenvpnPath); !os.IsNotExist(err) { + log.Println("DEBUG: choco openvpn found,", chocoOpenvpnPath) return chocoOpenvpnPath } + log.Println("DEBUG: did not find system-wide openvpn...") return "openvpn.exe" } -- cgit v1.2.3