From 7493fce0e3b9417e67bbbd4068157d5d37116c34 Mon Sep 17 00:00:00 2001 From: izk666 Date: Mon, 1 Feb 2021 23:55:53 +0000 Subject: [PATCH] I've modified your script with some enhancements: 1. Let the user choose the firefox flavor (regular or ESR) without editing the script 2. Apply the librewolf patch directly after installing (No 7za) 3. Remove the telemetry that points to firefox.settings.services.mozilla.com (issue #10) --- package.ps1 | 97 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/package.ps1 b/package.ps1 index f33e289..a7cb4db 100644 --- a/package.ps1 +++ b/package.ps1 @@ -1,30 +1,89 @@ -# delete old things... -Remove-Item -Path firefox.exe -Force -Remove-Item -Path librewolf -Force +Import-Module BitsTransfer +$ProgramName = "*Mozilla*Firefox*" +$installPath = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object { $_.getValue('DisplayName') -like $ProgramName } | ForEach-Object { $_.getValue('InstallLocation')} -# windows download version lastest win64 -$url = "https://download.mozilla.org/?product=firefox-latest-ssl&os=win64" +if (!$installPath) { -# windows download version lastest win32 -#$url = "https://download.mozilla.org/?product=firefox-latest-ssl&os=win" + # Choose firefox flavor + write-host "" + write-host "1 - Download Firefox" + write-host "2 - Download Firefox Extended Support Release" + write-host "" + write-host "E - Exit" + write-host "" + write-host -nonewline "Type your choice and press Enter: " + + $choice = read-host + switch -Regex ( $choice ) { + 1 { Write-Host "Firefox" -ForegroundColor Green; $url = "https://download.mozilla.org/?product=firefox-latest-ssl&os=win"} + 2 {Write-Host "Firefox ESR" -ForegroundColor Green; $url = "https://download.mozilla.org/?product=firefox-esr-latest-ssl&os=win"} + default { exit } + } + if ([IntPtr]::size -eq 8) { # Check if the system is 64bit and download the correct version + $url += "64" + } -$downloadfile = "$PSScriptRoot\firefox.exe" + $downloadfile = "\FirefoxInstaller.exe" + Write-Output "Downloading firefox..." + Start-BitsTransfer -Source $url -Destination $downloadfile -Write-Output "Downloading to $downloadfile" + Write-Output "" + Write-Output "Installing Firefox. Please, follow the wizard" + Start-Process $downloadfile -NoNewWindow -Wait -# download firefox -Invoke-WebRequest -Uri $url -outfile $downloadfile + # Check if firefox is running and close/kill + while ($firefox = Get-Process firefox -ErrorAction SilentlyContinue) { + $firefox.CloseMainWindow() + # kill after five seconds + Sleep 10 + if (!$firefox.HasExited) { + $firefox | Stop-Process -Force + } + Sleep 3 + } -Write-Output "Extracting $downloadfile to librewolf" -# extract with 7zip -& "$PSScriptRoot\7za.exe" x -olibrewolf .\firefox.exe + # Check if firefox is installed + Remove-Item $downloadfile + $installPath = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object { $_.getValue('DisplayName') -like $ProgramName } | ForEach-Object { $_.getValue('InstallLocation')} + if (!$installPath) { + Write-Output "Firefox can't be located. Process can't continue" + exit + } + +} else {Write-Host "Firefox is installed" } + + while ($firefox = Get-Process firefox -ErrorAction SilentlyContinue) { + $firefox.CloseMainWindow() + # kill after five seconds + Sleep 5 + if (!$firefox.HasExited) { + $firefox | Stop-Process -Force + } + Sleep 3 + } Write-Output "Delete files with privacy....." -# remove contact with mothership -Remove-Item -Path librewolf\core\crashreporter.exe -Force -Remove-Item -Path librewolf\core\updater.exe -Force -Remove-Item -Path librewolf\core\pingsender.exe -Force +Remove-Item -Path $installPath\crashreporter.exe -Force +Remove-Item -Path $installPath\updater.exe -Force +Remove-Item -Path $installPath\pingsender.exe -Force + +Write-Output "Extra privacy..." +$bytes = [System.IO.File]::ReadAllBytes("$installPath\omni.ja") +$hexString = [System.BitConverter]::ToString($bytes) +$offset = $hexString.IndexOf("3F-20-22-68-74-74-70-73-3A-2F-2F-66-69-72-65-66-6F-78-2E-73-65-74-74-69-6E-67-73-2E-73-65-72-76-69-63-65-73-2E-6D-6F-7A-69-6C-6C-61-2E-63-6F") +if ($offset -gt -1) { + $offset = $offset/3 + For ($i=3; $i -le 50; $i++) { + $bytes[$offset+$i] = 32 + } + [System.IO.File]::WriteAllBytes("$installPath\omni2.ja", $bytes) + Remove-Item -Path $installPath\omni.ja -Force + Rename-Item -Path $installPath\omni2.ja omni.ja +} Write-Output "Copy librewolf settings" -Copy-Item -Path "$PSScriptRoot\settings\*" -Destination "$PSScriptRoot\librewolf\core" -Recurse -force \ No newline at end of file +$scriptPath = Split-Path -Path $MyInvocation.MyCommand.Path +Copy-Item "$scriptPath\settings\*" -Destination "$installPath" -Recurse -Force + +Write-Output "Enjoy"