ThunderbirdBundle/Windows/Enigmail+pEp_Bundle.nsi

490 lines
11 KiB
Plaintext

# Enigmail pEp Bundle
# Reference
# http://nsis.sourceforge.net/Docs/Modern%20UI/Readme.html
# http://nsis.sourceforge.net/Docs/nsDialogs/Readme.html
# http://nsis.sourceforge.net/%22Orange%22_Modern_UI_Theme
!addplugindir NSIS\Plugins\x86-ansi
!include "MUI2.nsh"
# deprecated !include InstallOptions.nsh
Outfile "Enigmail+pEp_Bundle.exe"
Name "pEp Thunderbird with Enigmail Bundle"
InstallDir $APPDATA\pEp\BundleInstaller
# InstallDirRegKey HKCU "Software\Modern UI Test" ""
BrandingText "pEp Foundation. Privacy by Default."
; Vista+ user|admin
# The only guy that refuses to self-elevate is, wonder wonder... Gpg4win
RequestExecutionLevel user
Var isAdmin
Var EnvComSpec
# Var WINDIR
Var TbProfileDir
Var TbProfileDirFound
Var TbExec
Var TbExecFound
# ReserveFile getProfile.bat
# ReserveFile ioFile.ini
!define MUI_ICON "if_User_No-Frame_97832.ico"
# !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall-nsis.ico"
!define MUI_UNICON ${MUI_ICON}
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "held.bmp"
# !define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
!define MUI_HEADERIMAGE_UNBITMAP "held.bmp"
!define MUI_HEADERIMAGE_UNBITMAP_NOSTRETCH
!define MUI_HEADERIMAGE_RIGHT
# RRGGBBR
# !define MUI_BGCOLOR AAAAAA9
!define MUI_WELCOMEFINISHPAGE_BITMAP "held.bmp"
# !define MUI_WELCOMEFINISHPAGE_BITMAP_NOSTRETCH
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "held.bmp"
# !define MUI_UNWELCOMEFINISHPAGE_BITMAP_NOSTRETCH
# !define MUI_WELCOMEFINISHPAGE_INI nsis-pep.ini
Icon ${MUI_ICON}
UninstallIcon ${MUI_UNICON}
;--------------------------------
;Interface Settings
# - bad UX
#!define MUI_ABORTWARNING
!define MUI_UNABORTWARNING
# FIXME TODO: only for debugging:
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_UNFINISHPAGE_NOAUTOCLOSE
!define Trim "!insertmacro Trim"
!macro Trim ResultVar String
Push "${String}"
Call Trim
Pop "${ResultVar}"
!macroend
;--------------------------------
;Pages
!define MUI_WELCOMEPAGE_TITLE "Welcome-Title"
!define MUI_WELCOMEPAGE_TITLE_3LINES "Bla\nBla2\Bla3"
#!define MUI_WELCOMEPAGE_TEXT "Just text"
!insertmacro MUI_PAGE_WELCOME
# # Page custom CustomInstallers nsDialogsPageLeave
# !define MUI_PAGE_CUSTOMFUNCTION_POST DeselectBundleInstall
# !insertmacro MUI_PAGE_INSTFILES
#Function DeselectBundleInstall
# !insertmacro UnselectSection "Bundle Install"
#FunctionEnd
#!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt
!define MUI_PAGE_CUSTOMFUNCTION_PRE ComponentsPre
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ComponentsLeave
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE ProfilePre
#!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ProfileLeave
!define MUI_DIRECTORYPAGE_VARIABLE $TbProfileDir
!define MUI_PAGE_HEADER_TEXT "Thunderbird Profile"
!define MUI_PAGE_HEADER_SUBTEXT "Thunderbird Sub-Bla"
!insertmacro MUI_PAGE_DIRECTORY
# Second round
# Page custom CustomInstallers nsDialogsPageLeave
# !define MUI_PAGE_CUSTOMFUNCTION_PRE
!insertmacro MUI_PAGE_INSTFILES
# InstType "Privacy by Default"
# !define CIT_Special 1
# InstType "Online Update"
# http://nsis.sourceforge.net/Reference/Section
# We deliver the package with and without Thunderbird.
Var TbUrl
Var EnvWinDir
Var TbSetupReady
SectionGroup /e "Thunderbird" SECT_TB
Section "Download" INST_TB_DLOAD
#SectionIn 2
SetOutPath $PLUGINSDIR
Push 0
Pop $TbSetupReady
IfFileExists "$INSTDIR\Thunderbird_Setup.exe" TbDownloadOnDisk
StrCpy $TbUrl "https://download.mozilla.org/?product=thunderbird-latest&os=win&lang=en-US"
nsExec::ExecToLog '"$EnvWinDir\System32\bitsadmin.exe" /transfer "Thunderbird" /priority high "$TbUrl" "$INSTDIR\Thunderbird_Setup.exe"'
Pop $TbSetupReady
TbDownloadOnDisk:
SectionEnd
Section "Install" INST_TB
#SectionIn 1 2
MessageBox MB_OK "Install!$\n$0"
StrCmp $TbSetupReady 0 +1 NoTbSetupReady
nsExec::ExecToLog '"$INSTDIR\Thunderbird_Setup.exe" /S'
Pop $0
NoTbSetupReady:
SectionEnd
Section "New Profile" INST_TB_NEWPROF
# SectionIn 1 2
# Repeat
SectionEnd
Section "Select Profile" INST_TB_SELPROF
# SectionIn 1 2
# Repeat
SectionEnd
SectionGroupEnd
Section "Gpg4win" INST_GPGWIN
SectionIn RO
SetOutPath $INSTDIR\gpg4win
File gpg4win.ini
IfFileExists "$PROGRAMFILES32\GnuPG\bin\gpg.exe" Gpg4winInstalled
File gpg4win-3.1.1.exe
File gpg4win_setup.bat
# There are thousand ways gpg4win does NOT what it was asked,
# this way it works but the UAC prompt remains in background :(
nsExec::ExecToLog 'gpg4win_setup.bat gpg4win-3.1.1.exe'
Pop $0
Gpg4winInstalled:
CreateDirectory "$APPDATA\gnupg"
SetOutPath "$APPDATA\gnupg"
IfFileExists gpg.conf +2
File /oname=gpg.conf gpg-pep.conf
IfFileExists gpg-agent.conf +2
File /oname=gpg-agent.conf gpg-agent-pep.conf
IfFileExists gpa.conf +2
File /oname=gpa.conf gpa-pep.conf
SectionEnd
Section "Enigmail" INST_ENIGMAIL
#SectionIn 1 2 RO
SectionIn RO
CreateDirectory $TbProfileDir\extensions\staged
SetOutPath $TbProfileDir\extensions\staged
File "/oname={847b3a00-7ab1-11d4-8f02-006008948af5}.xpi" enigmail-2.0.7.xpi
File "/oname={847b3a00-7ab1-11d4-8f02-006008948af5}.json" staged.json
SectionEnd
Section "pEp Adapter" INST_MDA
#SectionIn 1 2 RO
SectionIn RO
# CreateDirectory
SetOutPath $TbProfileDir
File /a /r pepmda\
SectionEnd
Function ComponentsPre
# Set selected and readonly, deselecting in ComponentsPost
#IntOp $0 ${SF_SELECTED} | ${SF_RO}
#SectionSetFlags ${INST_BUNDLE} $0
# ----------------------------------------------
StrCmp $TbExecFound 0 FoundTb NotFoundTb
FoundTb:
IntOp $0 ${SF_RO} | 0
SectionSetFlags ${INST_TB_DLOAD} $0
# IntOp $0 ${SF_RO} | 0
IntOp $0 0 | 0
SectionSetFlags ${INST_TB} $0
Goto FoundTbEnd
NotFoundTb:
IntOp $0 ${SF_SELECTED} | ${SF_RO}
SectionSetFlags ${INST_TB_DLOAD} $0
IntOp $0 ${SF_SELECTED} | 0
SectionSetFlags ${INST_TB} $0
FoundTbEnd:
# ----------------------------------------------
StrCmp $TbProfileDirFound 0 FoundTbProf NotFoundTbProf
FoundTbProf:
IntOp $0 0 | ${SF_RO}
SectionSetFlags ${INST_TB_NEWPROF} $0
# We keep the Select Profile step always selectable
# but we don't activate it, as the automatic selection
# is OK for most users
IntOp $0 0 | 0
SectionSetFlags ${INST_TB_SELPROF} $0
Goto FoundTbProfEnd
NotFoundTbProf:
IntOp $0 ${SF_SELECTED} | ${SF_RO}
SectionSetFlags ${INST_TB_NEWPROF} $0
IntOp $0 0 | 0
SectionSetFlags ${INST_TB_SELPROF} $0
FoundTbProfEnd:
FunctionEnd
Function ComponentsLeave
#IntOp $0 0 | ${SF_RO}
#SectionSetFlags ${INST_BUNDLE} $0
FunctionEnd
Function ProfilePre
StrCpy $TbExec "TB_NOT_FOUND"
nsExec::ExecToStack '"$EnvComSpec" /C "$PLUGINSDIR\getProfile.bat" getexe'
Pop $TbExecFound
Pop $TbExec
${Trim} $TbExec $TbExec
nsExec::ExecToLog '"$TbExec" -silent -no-remote -createProfile default'
Pop $0
# TODO: Fail installation if this fails
#WaitForProfile:
# IfFileExists "$INSTDIR\Thunderbird_Setup.exe" TbDownloadOnDisk
StrCpy $TbProfileDir "NO_PROFILE_DIR"
nsExec::ExecToStack '"$EnvComSpec" /C "$PLUGINSDIR\getProfile.bat" getprofile'
Pop $TbProfileDirFound
Pop $TbProfileDir
${Trim} $TbProfileDir $TbProfileDir
# IfFileExists "$TbProfileDir" +1 WaitForProfile
# Skip the section if component not selected (using default from script)
SectionGetFlags ${INST_TB_SELPROF} $0
IntOp $0 $0 & ${SF_SELECTED}
StrCmp $0 ${SF_SELECTED} +2 +1
Abort
FunctionEnd
Function ProfileLeave
MessageBox MB_OK "On Leave '$0'"
FunctionEnd
!define MUI_FINISHPAGE_RUN $TbExec
!define MUI_FINISHPAGE_RUN_TEXT "Start Thunderbird"
!define MUI_FINISHPAGE_RUN_PARAMETERS
!define MUI_FINISHPAGE_RUN_NOTCHECKED
# !define MUI_FINISHPAGE_RUN_FUNCTION
!define MUI_FINISHPAGE_SHOWREADME https://pep.coop/cryptoparty/bundle-start.html
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Continue with instructions online"
# !define MUI_FINISHPAGE_SHOWREADME_TEXT
# !define MUI_FINISHPAGE_SHOWREADME_FUNCTION fn
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_LINK "Important: Join and support the pEp Cooperative today!"
!define MUI_FINISHPAGE_LINK_LOCATION https://software.pep.foundation/ping.html
!define MUI_FINISHPAGE_LINK_COLOR 03aa4b
!insertmacro MUI_PAGE_FINISH
# Uninstallers!
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Installer Sections
#### !insertmacro INSTALLOPTIONS_WRITE "ioFile.ini" "Field #" "Name" "Value"
Function .onInit
#!insertmacro INSTALLOPTIONS_EXTRACT "ioFile.ini"
# StrCpy $1 ${secBSPnew} ; Gotta remember which section we are at now...
# SectionGetFlags ${SecBSPnew} $0
# IntOp $0 $0 | ${SF_SELECTED}
# SectionSetFlags ${SecBSPnew} $0
ExpandEnvStrings $EnvComSpec %COMSPEC%
ExpandEnvStrings $EnvWinDir %WINDIR%
InitPluginsDir
File "/oname=$PLUGINSDIR\getProfile.bat" getProfile.bat
StrCpy $TbExec "TB_NOT_FOUND"
nsExec::ExecToStack '"$EnvComSpec" /C "$PLUGINSDIR\getProfile.bat" getexe'
Pop $TbExecFound
Pop $TbExec
${Trim} $TbExec $TbExec
nsExec::ExecToStack '"$EnvComSpec" /C "$PLUGINSDIR\getProfile.bat" getprofile'
Pop $TbProfileDirFound
Pop $TbProfileDir
${Trim} $TbProfileDir $TbProfileDir
nsExec::ExecToStack 'taskkill /F /IM pep-json-server.exe'
Pop $0
Pop $0
# File ioFile.ini
#File getProfile.bat
# File install.bat
# File installSettings.bat
# File staged.json
FunctionEnd
Function .onSelChange
#SectionGetFlags $1 $0
#IntOp $0 $0 & ${SECTION_OFF}
#SectionSetFlags $1 $0
FunctionEnd
Function Trim
Exch $R1 ; Original string
Push $R2
Loop:
StrCpy $R2 "$R1" 1
StrCmp "$R2" " " TrimLeft
StrCmp "$R2" "$\r" TrimLeft
StrCmp "$R2" "$\n" TrimLeft
StrCmp "$R2" "$\t" TrimLeft
GoTo Loop2
TrimLeft:
StrCpy $R1 "$R1" "" 1
Goto Loop
Loop2:
StrCpy $R2 "$R1" 1 -1
StrCmp "$R2" " " TrimRight
StrCmp "$R2" "$\r" TrimRight
StrCmp "$R2" "$\n" TrimRight
StrCmp "$R2" "$\t" TrimRight
GoTo Done
TrimRight:
StrCpy $R1 "$R1" -1
Goto Loop2
Done:
Pop $R2
Exch $R1
FunctionEnd
Section "Uninstall"
Delete $INSTDIR\UninstallInstaller.exe
# RMDir "$INSTDIR"
# DeleteRegKey /ifempty HKCU "Software\Modern UI Test"
SectionEnd