-
Notifications
You must be signed in to change notification settings - Fork 15
/
windows.ps1
34 lines (28 loc) · 1.18 KB
/
windows.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
$VSN = "1.4.6"
# build the filename for the Zip archive and exe file
$FileName = "mmdbctl_$($VSN)_windows_amd64"
$ZipFileName = "$($FileName).zip"
# download and extract zip
Invoke-WebRequest -Uri "https://github.com/ipinfo/mmdbctl/releases/download/mmdbctl-$VSN/$FileName.zip" -OutFile ./$ZipFileName
Unblock-File ./$ZipFileName
Expand-Archive -Path ./$ZipFileName -DestinationPath $env:LOCALAPPDATA\mmdbctl -Force
# delete if already exists
if (Test-Path "$env:LOCALAPPDATA\mmdbctl\mmdbctl.exe") {
Remove-Item "$env:LOCALAPPDATA\mmdbctl\mmdbctl.exe"
}
Rename-Item -Path "$env:LOCALAPPDATA\mmdbctl\$FileName.exe" -NewName "mmdbctl.exe"
# setting up env.
$PathContent = [Environment]::GetEnvironmentVariable('path', 'Machine')
$mmdbctlPath = "$env:LOCALAPPDATA\mmdbctl"
# if Path already exists
if ($PathContent -ne $null) {
if (-Not($PathContent -split ';' -contains $mmdbctlPath)) {
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";$env:LOCALAPPDATA\mmdbctl", "Machine")
}
}
else {
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";$env:LOCALAPPDATA\mmdbctl", "Machine")
}
# cleaning files
Remove-Item -Path ./$ZipFileName
"You can use mmdbctl now."