-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathinstall.ps1
46 lines (35 loc) · 1.34 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
#!/usr/bin/env pwsh
# edited from deno_install
$ErrorActionPreference = 'Stop'
$BinDir = "$Home\.neucn\bin"
$DownloadedZip = "$env:Temp\ipgw.zip"
$TargetPath = "$BinDir\ipgw.exe"
$Target = if ([System.Environment]::Is64BitOperatingSystem) {
"windows-amd64"
} else {
"windows-386"
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$DownloadURL = "https://github.com/neucn/ipgw/releases/latest/download/ipgw-${Target}.zip"
if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}
Invoke-WebRequest $DownloadURL -OutFile $DownloadedZip -UseBasicParsing
if (Get-Command Expand-Archive -ErrorAction SilentlyContinue) {
Expand-Archive $DownloadedZip -Destination $BinDir -Force
} else {
if (Test-Path $TargetPath) {
Remove-Item $TargetPath
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::ExtractToDirectory($DownloadedZip, $BinDir)
}
Remove-Item $DownloadedZip
$User = [EnvironmentVariableTarget]::User
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
if (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) {
[Environment]::SetEnvironmentVariable('Path', "$Path;$BinDir", $User)
$Env:Path += ";$BinDir"
}
Write-Output "ipgw was installed successfully to $TargetPath"
Write-Output "Run 'ipgw --help' to get started"