From 5c85cdb28130eeced1d86c0228d70646ec9ca0a3 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Tue, 10 Jul 2018 17:43:57 +0200 Subject: [pkg] cross build windows installer --- .gitignore | 1 + Makefile | 20 ++++++- win/Makefile | 2 +- win/RiseupVPN-installer.nsi | 127 -------------------------------------------- win/generate.py | 8 ++- win/template.nsi | 2 +- 6 files changed, 27 insertions(+), 133 deletions(-) delete mode 100755 win/RiseupVPN-installer.nsi diff --git a/.gitignore b/.gitignore index 38a4274..4b7eda5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ dist/* __pycache__ helper/helper helper/pid +win/*-installer.nsi diff --git a/Makefile b/Makefile index 9741257..0cb2208 100755 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ VERSION = $(shell git -C `go env GOPATH`/src/$(SYSTRAY) describe --tags) # ----------------------------------------------------------------------------- # Windows # ----------------------------------------------------------------------------- +CROSS_FLAGS = CGO_ENABLED=1 GOARCH=386 GOOS=windows CC="/usr/bin/i686-w64-mingw32-gcc" CGO_LDFLAGS="-lssp" CXX="i686-w64-mingw32-c++" deps_win: choco install -y golang python upx nssm nsis wget 7zip @@ -24,17 +25,27 @@ openvpn_win: copy .\staging\openvpn\openvpn.exe .\staging copy .\staging\openvpn\*.dll .\staging helper_win: - go build -ldflags "-s -w" -o $(STAGING)/$(HELPER_BIN).exe .\helper + go build -ldflags "-s -w" -o $(STAGING)/$(HELPER_BIN).exe ./helper upx $(STAGING)/$(HELPER_BIN).exe systray_win: go get -tags "standalone" -u $(SYSTRAY) powershell '$$gopath=go env GOPATH;$$version=git -C $$gopath/src/$(SYSTRAY) describe --tags; go build -tags "standalone" -ldflags "-H windowsgui -s -w -X main.version=$$version" -o $(STAGING)/$(SYSTRAY_BIN).exe $(SYSTRAY)' + upx $(STAGING)/$(SYSTRAY_BIN).exe build_win: staging\nssm.exe helper_win systray_win # since it's tedious, I assume you did bootstrap openvpn_win manually already. echo "[+] building windows" if not exist dist mkdir dist - make -C win + powershell '$$gopath=go env GOPATH;$$version=git -C $$gopath/src/$(SYSTRAY) describe --tags; $(MAKE) -C win VERSION=$$version' "C:\Program Files (x86)\NSIS\makensis.exe" win/RiseupVPN-installer.nsi +build_cross_win: staging/nssm.exe + echo "!define VERSION $(VERSION)" > $(STAGING)/version.nsh + $(CROSS_FLAGS) $(MAKE) helper_win + $(CROSS_FLAGS) go get -tags "standalone" -u $(SYSTRAY) + $(CROSS_FLAGS) go build -tags "standalone" -ldflags "-H windowsgui -s -w -X main.version=$(VERSION)" -o $(STAGING)/$(SYSTRAY_BIN).exe $(SYSTRAY) + upx $(STAGING)/$(SYSTRAY_BIN).exe + mkdir -p dist + make -C win VERSION=$(VERSION) + makensis win/RiseupVPN-installer.nsi # ----------------------------------------------------------------------------- # OSX @@ -86,3 +97,8 @@ clean: staging\nssm.exe: xcopy /y "C:\ProgramData\chocolatey\lib\NSSM\tools\nssm.exe" $(STAGING) +staging/nssm.exe: + wget https://nssm.cc/release/nssm-2.24.zip -O $(STAGING)/nssm.zip + unzip $(STAGING)/nssm.zip -d $(STAGING) + mv $(STAGING)/nssm-*/win32/nssm.exe $(STAGING) + rm -rf $(STAGING)/nssm-* $(STAGING)/nssm.zip diff --git a/win/Makefile b/win/Makefile index f8b33bb..e2a1c0b 100755 --- a/win/Makefile +++ b/win/Makefile @@ -1,2 +1,2 @@ generate: - python ./generate.py + python ./generate.py $(VERSION) diff --git a/win/RiseupVPN-installer.nsi b/win/RiseupVPN-installer.nsi deleted file mode 100755 index 5c17018..0000000 --- a/win/RiseupVPN-installer.nsi +++ /dev/null @@ -1,127 +0,0 @@ -SetCompressor /SOLID lzma - -!define PRODUCT_PUBLISHER "LEAP Encryption Access Project" -!include "MUI2.nsh" - -Name "RiseupVPN" -Outfile "..\dist\RiseupVPN-installer.exe" -;TODO make the installdir configurable - and set it in the registry. -InstallDir "C:\Program Files\RiseupVPN\" -RequestExecutionLevel admin - -!include FileFunc.nsh -!insertmacro GetParameters -!insertmacro GetOptions - -;Macros - -!macro SelectByParameter SECT PARAMETER DEFAULT - ${GetOptions} $R0 "/${PARAMETER}=" $0 - ${If} ${DEFAULT} == 0 - ${If} $0 == 1 - !insertmacro SelectSection ${SECT} - ${EndIf} - ${Else} - ${If} $0 != 0 - !insertmacro SelectSection ${SECT} - ${EndIf} - ${EndIf} -!macroend - - -!define BITMAP_FILE riseupvpn.bmp - -!define MUI_ICON "..\assets\riseupvpn.ico" -!define MUI_UNICON "..\assets\riseupvpn.ico" - -!define MUI_WELCOMEPAGE_TITLE "RiseupVPN" -!define MUI_WELCOMEPAGE_TEXT "This will install RiseupVPN in your computer. RiseupVPN is a simple, fast and secure VPN Client, powered by Bitmask. \n This VPN service is run by donations from people like you." -#!define MUI_WELCOMEFINISHPAGE_BITMAP "riseup.png" - -!insertmacro MUI_PAGE_WELCOME -!insertmacro MUI_PAGE_INSTFILES -!insertmacro MUI_PAGE_FINISH - - - -Section "InstallFiles" - SetOutPath $INSTDIR - WriteUninstaller $INSTDIR\uninstall.exe - - ;Start Menu - createDirectory "$SMPROGRAMS\RiseupVPN\" - createShortCut "$SMPROGRAMS\RiseupVPN\RiseupVPN.lnk" "$INSTDIR\bitmask-systray.exe" "" "$INSTDIR\riseupvpn.ico" - - File "readme.txt" - File "..\staging\nssm.exe" - File "..\assets\riseupvpn.ico" - - - File ..\staging\bitmask_helper.exe - File ..\staging\bitmask-systray.exe - File ..\staging\libcrypto-1_1-x64.dll - File ..\staging\liblzo2-2.dll - File ..\staging\libpkcs11-helper-1.dll - File ..\staging\libssl-1_1-x64.dll - File ..\staging\padlock.dll - File ..\staging\openvpn\openvpn.exe - File ..\staging\openvpn\tap-windows.exe - - -SectionEnd - -Section "InstallService" - ; Easy service management thanks to nssm - ExecWait '"$INSTDIR\nssm.exe" remove riseupvpn-helper confirm' - ExecWait '"$INSTDIR\nssm.exe" install riseupvpn-helper "$INSTDIR\bitmask_helper.exe"' - ExecWait '"$INSTDIR\nssm.exe" set riseupvpn-helper AppDirectory "$INSTDIR"' - ExecWait '"$INSTDIR\nssm.exe" start riseupvpn-helper' - - ; why are these here? - Delete "C:\riseupvpn.ico" - Delete "C:\riseupvpn.png" -SectionEnd - -Section /o "TAP Virtual Ethernet Adapter" SecTAP - ; Adapted from the windows nsis installer from OpenVPN (openvpn-build repo). - DetailPrint "Installing TAP (may need confirmation)..." - ExecWait '"$INSTDIR\tap-windows.exe" /SELECT_UTILITIES=1' - ;Making it explicit for now. It looks like the /S flag is "silent", isn't it? - ;ExecWait '"$INSTDIR\tap-windows.exe" /S /SELECT_UTILITIES=1' - Pop $R0 # return value/error/timeout - WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\RiseupVPN" "tap" "installed" - DetailPrint "TAP installed!" -SectionEnd - -Section "Uninstall" - ExecWait '"$INSTDIR"\nssm.exe stop riseupvpn-helper' - ExecWait '"$INSTDIR"\nssm.exe remove riseupvpn-helper confirm' - - Delete $INSTDIR\readme.txt - Delete $INSTDIR\nssm.exe - - - Delete $INSTDIR\riseupvpn.ico - Delete $INSTDIR\openssl.exe - Delete $INSTDIR\openvpn.exe - Delete $INSTDIR\ssleay32.dll - Delete $INSTDIR\libeay32.dll - Delete $INSTDIR\liblzo2-2.dll - Delete $INSTDIR\libpkcs11-helper-1.dll - Delete $INSTDIR\bitmask_helper.exe - Delete $INSTDIR\bitmask-systray.exe - Delete $INSTDIR\tap-windows.exe - - - ; uninstaller must be always the last thing to remove - Delete $INSTDIR\uninstall.exe -SectionEnd - -Function .onInit - !insertmacro SelectByParameter ${SecTAP} SELECT_TAP 1 -FunctionEnd - -;---------------------------------------- -;Languages - -!insertmacro MUI_LANGUAGE "English" diff --git a/win/generate.py b/win/generate.py index efc2108..b5fc96f 100755 --- a/win/generate.py +++ b/win/generate.py @@ -4,6 +4,7 @@ generate.py Generate a NSI installer for a given provider. """ +import sys from string import Template from provider import * @@ -11,7 +12,9 @@ from provider import * TEMPLATE = 'template.nsi' INSTALLER = APP_NAME + '-installer.nsi' - +VERSION = sys.argv[1] +if not VERSION: + VERSION = "installer" def get_files(which): files = "\n" @@ -34,7 +37,8 @@ vardict = { 'app_name_lower': APP_NAME.lower(), 'url': URL, 'extra_install_files': get_files('install'), - 'extra_uninstall_files': get_files('uninstall') + 'extra_uninstall_files': get_files('uninstall'), + 'version': VERSION } diff --git a/win/template.nsi b/win/template.nsi index 1abe472..0f6d1c1 100755 --- a/win/template.nsi +++ b/win/template.nsi @@ -4,7 +4,7 @@ SetCompressor /SOLID lzma !include "MUI2.nsh" Name "$app_name" -Outfile "..\dist\$app_name-installer.exe" +Outfile "..\dist\$app_name-$version.exe" ;TODO make the installdir configurable - and set it in the registry. InstallDir "C:\Program Files\$app_name\" RequestExecutionLevel admin -- cgit v1.2.3