This repository has been archived by the owner on May 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
/
install.ps1
59 lines (46 loc) · 2.07 KB
/
install.ps1
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
# Installs the native manifest on windows
#
$app = 'com.dannyvankooten.browserpass'
$dirpath = Join-Path -Path $env:localappdata -ChildPath 'browserpass'
$ff_jsonpath = Join-Path -Path $dirpath -ChildPath "$app-firefox.json"
$chrome_jsonpath = Join-Path -Path $dirpath -ChildPath "$app-chrome.json"
# Make our local directory
new-item -type Directory -Path $dirpath -force
# copy our bin to local directory
& Copy-Item browserpass-windows64.exe $dirpath
# copy the native messaging manifest
$ffile = gc firefox-host.json
$ffile -replace '%%replace%%', ((Join-Path -Path $dirpath -ChildPath 'browserpass-windows64.exe' | ConvertTo-json) -replace '^"|"$', "") | Out-File -Encoding UTF8 $ff_jsonpath
$cfile = gc chrome-host.json
$cfile -replace '%%replace%%', ((Join-Path -Path $dirpath -ChildPath 'browserpass-windows64.exe' | ConvertTo-json) -replace '^"|"$', "") | Out-File -Encoding UTF8 $chrome_jsonpath
Write-Host ""
Write-Host "Which browser are you using?"
Write-Host "1) Firefox"
Write-Host "2) Chrome"
$browser = Read-Host
$allUsers = Read-Host "Install for all users? (y/n) [n]"
$installDest = "cu" # Current User
switch -wildcard ($allUsers) {
"y*" { $installDest = "lm"; Break; }
"n*" { $installDest = "cu"; Break; }
default { $installDest = "cu" }
}
$browserToUse = ""
switch -regex ($browser) {
'^1$|^f' { $browserToUse = "Mozilla"; Break; }
'^2$|^c' { $browserToUse = "Google/Chrome"; Break; }
default {$browserToUse = "unknown"}
}
If ($installDest -eq "lm" -And -NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "Please re-run this script with Admin rights!"
exit
}
$regPath = "hk{0}:\Software\{1}\NativeMessagingHosts" -f $installDest, $browserToUse
If (-NOT (Test-Path -Path $regPath)) {
New-Item -Path $regPath -force
}
New-Item -Path "$regPath\$app" -force
New-ItemProperty -Path "$regPath\$app"`
-Name '(Default)'`
-Value $(If ($browserToUse -eq "Mozilla") {$ff_jsonpath} Else {$chrome_jsonpath})