Pier Angelo Vendrame pushed to branch main at The Tor Project / Applications / tor-browser-build
Commits: b9a8c62b by Pier Angelo Vendrame at 2023-02-14T15:18:01+01:00 Bug 40776: Create both a system-wide and a portable Privacy Browser installer
- - - - -
3 changed files:
- projects/browser/build - projects/browser/pe_checksum_fix.py - projects/browser/windows-installer.nsi
Changes:
===================================== projects/browser/build ===================================== @@ -285,9 +285,14 @@ done export PATH="/var/tmp/dist/nsis/bin:$PATH"
mv $rootdir/windows-installer $distdir/windows-installer - cat > $distdir/windows-installer/browser.nsi << 'BROWSER_NSI' + cat > $distdir/windows-installer/browser-portable.nsi << 'BROWSER_NSI' [% INCLUDE 'windows-installer.nsi' %] BROWSER_NSI + [% IF c('var/privacy-browser') -%] + cat > $distdir/windows-installer/browser-system.nsi << 'BROWSER_NSI' +[% INCLUDE 'windows-installer.nsi' system_install_mode = 1 %] +BROWSER_NSI + [% END -%] mv ${TB_STAGE_DIR} $distdir/windows-installer/"[% c('var/Project_Name') %]" mv $distdir/windows-installer ${TB_STAGE_DIR} [% END %] @@ -357,13 +362,15 @@ cd $distdir [% ELSIF c("var/windows") %] find "$PKG_DIR" -exec [% c("touch") %] {} ; pushd "$PKG_DIR" - makensis browser.nsi + makensis browser-portable.nsi # Working around NSIS braindamage - mv [% c("var/projectname") %]-install.exe browser-install-tmp.exe - python3 $rootdir/pe_checksum_fix.py - mv browser-install-tmp2.exe [% c("var/projectname") %]-install.exe - rm browser-install-tmp.exe - mv [% c("var/projectname") %]-install.exe $OUTDIR/[% c("var/projectname") %]-install[% IF c("var/windows-x86_64") %]-win64[% END %]-[% c("var/torbrowser_version") %]_${PKG_LOCALE}.exe + python3 $rootdir/pe_checksum_fix.py browser-install.exe + mv browser-install.exe $OUTDIR/[% c("var/projectname") %]-install[% IF c("var/windows-x86_64") %]-win64[% END %]-[% c("var/torbrowser_version") %]_${PKG_LOCALE}.exe + [% IF c('var/privacy-browser') -%] + makensis browser-system.nsi + python3 $rootdir/pe_checksum_fix.py browser-install.exe + mv browser-install.exe $OUTDIR/[% c("var/projectname") %]-systeminstall[% IF c("var/windows-x86_64") %]-win64[% END %]-[% c("var/torbrowser_version") %]_${PKG_LOCALE}.exe + [% END -%] popd [% END %] rm -rf $distdir/${PKG_DIR}
===================================== projects/browser/pe_checksum_fix.py ===================================== @@ -43,14 +43,20 @@ recalculates the PE-file checksum. Details of the discussion can be found in bug Thanks to a cypherpunk for this workaround idea. """
-import pefile; +import pefile +import sys
-f = open('browser-install-tmp.exe', 'rb') -exe = f.read() -f.close() + +if len(sys.argv) < 2: + print('Usage: {} exe-name'.format(sys.argv[0])) + sys.exit(1) + +exename = sys.argv[1] +with open(exename, 'rb') as f: + exe = f.read() remainder = len(exe) % 8 if remainder > 0: - exe += bytes('\0' * (8 - remainder), 'utf-8') + exe += b'\0' * (8 - remainder) pef = pefile.PE(data=exe, fast_load=True) pef.OPTIONAL_HEADER.CheckSum = pef.generate_checksum() -pef.write(filename='browser-install-tmp2.exe') +pef.write(filename=exename)
===================================== projects/browser/windows-installer.nsi ===================================== @@ -5,6 +5,7 @@ ;-------------------------------- ;Modern UI
+ !include "FileFunc.nsh" !include "MUI2.nsh" !include "LogicLib.nsh" !include "WinVer.nsh" @@ -12,25 +13,38 @@ ;-------------------------------- ;General
- ; location of Tor/Base/Privacy Browser to put into installer + ;Location of Tor/Base/Privacy Browser to put into installer !define PROGRAM_SOURCE ".[% c('var/Project_Name') %]"
Name "[% c('var/Project_Name') %]" - OutFile "[% c('var/projectname') %]-install.exe" + OutFile "browser-install.exe"
;Default installation folder +[% IF system_install_mode -%] + InstallDir "$PROGRAMFILES[% c('var/Project_Name') %]" +[% ELSE -%] InstallDir "$DESKTOP[% c('var/Project_Name') %]" +[% END -%]
;Best (but slowest) compression SetCompressor /SOLID lzma SetCompressorDictSize 32
;Request application privileges for Windows Vista +[% IF system_install_mode -%] + RequestExecutionLevel admin +[% ELSE -%] RequestExecutionLevel user +[% END -%]
;Support HiDPI displays ManifestDPIAware true
+[% IF system_install_mode -%] + ;Registry keys to uninstall system-wide installs + !define UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall[% c('var/ProjectName') %]" +[% END -%] + ;-------------------------------- ;Interface Configuration
@@ -133,16 +147,49 @@ Section "[% c('var/Project_Name') %]" SecBrowser
SetOutPath "$INSTDIR" +[% IF !system_install_mode -%] File /r "${PROGRAM_SOURCE}*.*" - SetOutPath "$INSTDIR\Browser" CreateShortCut "$INSTDIR\Start [% c('var/Project_Name') %].lnk" "$INSTDIR\Browser[% c('var/exe_name') %].exe" +[% ELSE -%] + File /r "${PROGRAM_SOURCE}\Browser*.*" + + ;Enable system-wide install in the browser + FileOpen $0 "$INSTDIR\system-install" w + FileClose $0 + + ;Write the uninstaller + WriteUninstaller $INSTDIR\uninstall.exe + + ;Add the uninstaller to the control panel + WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "[% c('var/Project_Name') %]" + WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" "$"$INSTDIR\uninstall.exe$"" + WriteRegStr HKLM "${UNINST_KEY}" "QuietUninstallString" "$"$INSTDIR\uninstall.exe$" /S" + WriteRegStr HKLM "${UNINST_KEY}" "DisplayIcon" "$"$INSTDIR[% c('var/exe_name') %].exe$"" + WriteRegDWORD HKLM "${UNINST_KEY}" "NoModify" "1" + WriteRegDWORD HKLM "${UNINST_KEY}" "NoRepair" "1" + ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 + IntFmt $0 "0x%08X" $0 + WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" "$0" +[% END -%]
SectionEnd
-Function CreateShortcuts +[% IF system_install_mode -%] +Section "Uninstall" + RMDir /r "$INSTDIR" + DeleteRegKey HKLM "${UNINST_KEY}" + SetShellVarContext all + Delete "$SMPROGRAMS[% c('var/Project_Name') %].lnk" + Delete "$DESKTOP[% c('var/Project_Name') %].lnk" +SectionEnd +[% END -%]
- CreateShortCut "$SMPROGRAMS\Start [% c('var/Project_Name') %].lnk" "$INSTDIR\Browser[% c('var/exe_name') %].exe" - CreateShortCut "$DESKTOP\Start [% c('var/Project_Name') %].lnk" "$INSTDIR\Browser[% c('var/exe_name') %].exe" +Function CreateShortcuts +[% IF system_install_mode -%] + SetShellVarContext all +[% END -%] + CreateShortCut "$SMPROGRAMS[% c('var/Project_Name') %].lnk" "$INSTDIR[% IF !system_install_mode -%]Browser[% END -%][% c('var/exe_name') %].exe" + CreateShortCut "$DESKTOP[% c('var/Project_Name') %].lnk" "$INSTDIR[% IF !system_install_mode -%]Browser[% END -%][% c('var/exe_name') %].exe"
FunctionEnd ;-------------------------------- @@ -181,7 +228,6 @@ ${If} ${FileExists} "$INSTDIR*.*" ${EndIf} FunctionEnd
- Function StartBrowser ExecShell "open" "$INSTDIR/Start [% c('var/Project_Name') %].lnk" FunctionEnd
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/b9...