-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup-firefox.ps1
More file actions
102 lines (83 loc) · 3.44 KB
/
setup-firefox.ps1
File metadata and controls
102 lines (83 loc) · 3.44 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
Write-Verbose "======= Firefox Setup =======" -Verbose
Function Get-DownloadDirectory {
(New-Object -ComObject Shell.Application).NameSpace("shell:Downloads").Self.Path
}
Function Download-Addons {
$Addons = @{
"Decentraleyes.zip" = "https://addons.mozilla.org/firefox/downloads/file/3539177/"
"NoScript.zip" = "https://addons.mozilla.org/firefox/downloads/file/3552502/"
"UBlock Origin.zip" = "https://addons.mozilla.org/firefox/downloads/file/3551054/"
"HTTPSEverywhere.zip" = "https://addons.mozilla.org/firefox/downloads/file/3528100/"
"Vimium.zip" = "https://addons.mozilla.org/firefox/downloads/file/3518684/"
}
$DownloadDirectory = Get-DownloadDirectory
$WebClient = New-Object net.webclient
$OutFiles = @()
foreach ($Addon in $Addons.GetEnumerator()) {
$OutFile = Join-Path -Path $DownloadDirectory -ChildPath $Addon.Name
if (-Not (Test-Path $OutFile -PathType Leaf)) {
Write-Verbose "Downloading $($Addon.Key)" -Verbose
$WebClient.Downloadfile($Addon.Value, $OutFile)
}
$OutFiles += $OutFile
}
$OutFiles
}
Function Extract-AddonIds($OutFiles) {
$DynamicAddonIds = @{
(Join-Path -Path $(Get-DownloadDirectory) -ChildPath "Vimium.zip") = "{d7742d87-e61d-4b78-b8a1-b469842139fa}"
}
$Ids = @()
Add-Type -assembly "system.io.compression.filesystem"
$Shell = New-Object -ComObject Shell.Application
foreach ($File in $OutFiles) {
if ($DynamicAddonIds.ContainsKey($File)) {
$Ids += $DynamicAddonIds[$File]
}
else {
$Zip = [io.compression.zipfile]::OpenRead($File)
$ManifestFile = $Zip.Entries | Where-Object { $_.Name -eq "manifest.json"}
$Stream = $ManifestFile.Open()
$Reader = New-Object IO.StreamReader($Stream)
$Content = $Reader.ReadToEnd()
$Reader.Close()
$Stream.Close()
$Zip.Dispose()
$Json = $Content | ConvertFrom-Json
if ($Json.PSObject.Properties.Name.Contains("applications")) {
$Ids += $Json.applications.gecko.id
}
ElseIf ($Json.PSObject.Properties.Name.Contains("browser_specific_settings")) {
$Ids += $Json.browser_specific_settings.gecko.id
}
}
}
$Ids
}
Function Rename-Addons($Files, $Ids) {
$RenamedFiles = @()
while ($Files) {
$File, $Files = $Files
$Id, $AddonIds = $AddonIds
$NewName = "$Id.xpi"
Rename-Item -Path $File -NewName $NewName
$RenamedFiles += $NewName
}
$RenamedFiles
}
Function Move-FilesToAddonDirectory($Files) {
$BasePath = Join-Path -Path $env:APPDATA -ChildPath "Mozilla\Firefox\Profiles\"
$Directories = Get-ChildItem $BasePath -directory
$CurrentProfile = $Directories.Where({$_.Name -match "default-release$"}, "First")
$ProfileDirectory = Join-Path -Path $BasePath -ChildPath $CurrentProfile.Name
$ExtensionDirectory = Join-Path -Path $ProfileDirectory -ChildPath "extensions"
Write-Verbose "Firefox Profile Directory: $ExtensionDirectory" -Verbose
foreach ($File in $Files) {
Write-Verbose "Installing Addon: $File" -Verbose
Move-Item -Path $File -Destination $ExtensionDirectory
}
}
$OutFiles = Download-Addons
$AddonIds = Extract-AddonIds $OutFiles
$RenamedFiles = Rename-Addons $OutFiles $AddonId
Move-FilesToAddonDirectory $RenamedFiles