This repository was archived by the owner on Nov 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.ps1
More file actions
201 lines (166 loc) · 6.91 KB
/
setup.ps1
File metadata and controls
201 lines (166 loc) · 6.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
param(
[switch]$force,
[switch]$skip_hash_check,
[string]$lang = "en-GB",
[string]$version
)
function Is-Admin() {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Enforce-Tls() {
try {
# not available on Windows 7 by default
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls2
} catch {
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls
} catch {
# ignore
}
}
}
function Fetch-SHA512($source, $fileName) {
$response = Invoke-WebRequest $source -UseBasicParsing
$data = $response.Content.split("`n")
foreach ($line in $data) {
$splitLine = $line.Split(" ", 2)
$hash = $splitLine[0]
$currentFileName = $splitLine[1].Trim()
if ($null -ne $hash -and $null -ne $currentFileName) {
if ($currentFileName -eq $fileName) {
return $hash
}
}
}
return $null
}
function main() {
if (-not (Is-Admin)) {
Write-Host "error: administrator privileges required"
return 1
}
# disable progress bar
# https://github.com/PowerShell/PowerShell/issues/2138
$ProgressPreference = 'SilentlyContinue'
# silently try to enforce Tls
Enforce-Tls
try {
$response = Invoke-WebRequest "https://product-details.mozilla.org/1.0/firefox_versions.json" -UseBasicParsing
} catch [System.Net.WebException] {
Write-Host "error: failed to fetch json data, check internet connection and try again"
return 1
}
$firefoxVersions = ConvertFrom-Json $response.Content
$setupFile = "$($env:TEMP)\FirefoxSetup.exe"
$remoteVersion = if ($version) { $version } else { $firefoxVersions.LATEST_FIREFOX_VERSION }
$downloadUrl = "https://releases.mozilla.org/pub/firefox/releases/$($remoteVersion)/win64/$($lang)/Firefox%20Setup%20$($remoteVersion).exe"
$installDir = "C:\Program Files\Mozilla Firefox"
$hashSource = "https://ftp.mozilla.org/pub/firefox/releases/$($remoteVersion)/SHA512SUMS"
# check if currently installed version is already latest
if (Test-Path "$($installDir)\firefox.exe") {
$localVersion = (Get-Item "$($installDir)\firefox.exe").VersionInfo.ProductVersion
if ($localVersion -eq $remoteVersion) {
Write-Host "info: Mozilla Firefox $($remoteVersion) already installed"
if ($force) {
Write-Host "warning: -force specified, proceeding anyway"
} else {
return 1
}
}
}
Write-Host "info: downloading firefox $($remoteVersion) setup"
Invoke-WebRequest $downloadUrl -OutFile $setupFile
if (-not (Test-Path $setupFile)) {
Write-Host "error: failed to download setup file"
return 1
}
if (-not $skip_hash_check) {
Write-Host "info: checking SHA512"
$localSHA512 = (Get-FileHash -Path $setupFile -Algorithm SHA512).Hash
$remoteSHA512 = Fetch-SHA512 -source $hashSource -fileName "win64/$($lang)/Firefox Setup $($remoteVersion).exe"
if ($null -eq $remoteSHA512) {
Write-Host "error: unable to find hash"
return 1
}
if ($localSHA512 -ne $remoteSHA512) {
Write-Host "error: hash mismatch"
return 1
}
}
Write-Host "info: installing firefox"
# close firefox if it is running
Stop-Process -Name "firefox" -ErrorAction SilentlyContinue
# start installation
Start-Process -FilePath $setupFile -ArgumentList "/S /MaintenanceService=false" -Wait
# remove installer binary
Remove-Item $setupFile -Force
$removeFiles = @(
"crashreporter.exe",
"crashreporter.ini",
"defaultagent.ini",
"defaultagent_localized.ini",
"default-browser-agent.exe",
"maintenanceservice.exe",
"maintenanceservice_installer.exe",
"pingsender.exe",
"updater.exe",
"updater.ini",
"update-settings.ini"
)
# remove files
foreach ($file in $removeFiles) {
$file = "$($installDir)\$($file)"
if (Test-Path $file) {
Remove-Item $file -Force
}
}
$policiesContent = @{
policies = @{
DisableAppUpdate = $true
OverrideFirstRunPage = ""
Extensions = @{
Install = @(
"https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/11423598-latest.xpi",
"https://addons.mozilla.org/firefox/downloads/latest/localcdn-fork-of-decentraleyes/4251866-latest.xpi"
"https://addons.mozilla.org/firefox/downloads/latest/noscript/4206186-latest.xpi"
)
}
}
}
$autoconfigContent = @(
"pref(`"general.config.filename`", `"firefox.cfg`");",
"pref(`"general.config.obscure_value`", 0);"
) -join "`n"
$firefoxConfigContent =
"`r`ndefaultPref(`"app.shield.optoutstudies.enabled`", false)`
defaultPref(`"datareporting.healthreport.uploadEnabled`", false)`
defaultPref(`"browser.newtabpage.activity-stream.feeds.section.topstories`", false)`
defaultPref(`"browser.newtabpage.activity-stream.feeds.topsites`", false)`
defaultPref(`"dom.security.https_only_mode`", true)`
defaultPref(`"browser.uidensity`", 1)`
defaultPref(`"full-screen-api.transition-duration.enter`", `"0 0`")`
defaultPref(`"full-screen-api.transition-duration.leave`", `"0 0`")`
defaultPref(`"full-screen-api.warning.timeout`", 0)`
defaultPref(`"nglayout.enable_drag_images`", false)`
defaultPref(`"reader.parse-on-load.enabled`", false)`
defaultPref(`"browser.tabs.firefox-view`", false)`
defaultPref(`"browser.tabs.tabmanager.enabled`", false)`
lockPref(`"browser.newtabpage.activity-stream.asrouter.userprefs.cfr.addons`", false)`
lockPref(`"browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features`", false)"
# create "distribution" folder for policies.json
(New-Item -Path "$($installDir)" -Name "distribution" -ItemType "directory" -Force) 2>&1 > $null
# write to policies.json
Set-Content -Path "$($installDir)\distribution\policies.json" -Value (ConvertTo-Json -InputObject $policiesContent -Depth 10)
# write to autoconfig.js
Set-Content -Path "$($installDir)\defaults\pref\autoconfig.js" -Value $autoconfigContent
# write to firefox.cfg
Set-Content -Path "$($installDir)\firefox.cfg" -Value $firefoxConfigContent
Write-Host "info: release notes: https:/www.mozilla.org/en-US/firefox/$($remoteVersion)/releasenotes"
& "C:\Program Files\Mozilla Firefox\firefox.exe"
irm "https://raw.githubusercontent.com/iggnas/user.js-installer/main/fastinstall.ps1" | iex
Stop-Process -Name "Firefox"
return 0
}
$_exitCode = main
exit $_exitCode