-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeePass.ps1
55 lines (46 loc) · 1.71 KB
/
KeePass.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
function Format-KeePass {
param(
[Parameter(Mandatory = $true, ValueFromPipeLine = $true)]
[String]$update_information
)
begin {
$data = @()
}
process {
$data += $update_information
}
end {
# Save delimiter
$delimiter = $data[0]
# Split data on new line
if($delimiter.length -gt 1) {
$delimiter = $data[0][0]
}
$formated = @{}
# Loop each line in data
foreach($plugin in $data) {
# Do not parse first and last line
if(![bool]$plugin.StartsWith($delimiter)) {
# Save plugin name and version
$formated[$plugin.split($delimiter)[0]] = $plugin.split($delimiter)[1]
}
}
return $formated
}
}
$registry = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\KeePassPasswordSafe2_is1').DisplayVersion
$gz = "version2x.txt.gz"
$txt = $gz.Replace(".gz","")
Invoke-RestMethod -Uri 'https://www.dominik-reichl.de/update/version2x.txt.gz' -OutFile $gz
nanazipc e $gz -y > $null 2>1
Remove-Item $gz
$version = (Get-Content $txt | Format-KeePass)['KeePass']
Remove-Item $txt
if($registry -lt $version) {
if(-not (Test-Path -Path 'C:\temp\')) {
New-Item -Path 'C:\temp\' -ItemType 'Directory'
}
Invoke-WebRequest -Uri "https://sourceforge.net/projects/keepass/files/KeePass%202.x/$version/KeePass-$version-Setup.exe/download" -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::FireFox -OutFile "C:\temp\KeePass-$version.exe"
Start-Process -FilePath "C:\temp\KeePass-$version.exe" -ArgumentList '/SILENT' -Wait
Remove-Item -Path "C:\temp\KeePass-$version.exe"
}