forked from cristianoliveira/ergo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
55 lines (40 loc) · 1.45 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
$installDir = "$Env:UserProfile\Ergo"
$downloadTo = "$Env:TEMP\ergo.exe"
function Test-RegistryValue {
param (
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]$Path,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]$Value
)
try {
Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null
return $true
}
catch {
return $false
}
}
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/cristianoliveira/ergo/master/.version" -OutFile .version
$v = Get-Content .version | Out-String
$v = $v.Trim()
Write-Host "Ergo $v will be installed to: $installDir"
Invoke-WebRequest -Uri "https://github.com/cristianoliveira/ergo/releases/download/$v/ergo.exe" -OutFile $downloadTo
If(!(Test-Path $installDir))
{
New-Item -ItemType Directory -Force -Path $installDir
}
Copy-Item -Path "$downloadTo" -Dest "$installDir\ergo.exe"
if(!(Test-Path "HKCU:\Environment"))
{
New-Item -Path "HKCU:\Environment" -Force
#reg add "HKCU\Environment" /v Path /f /t REG_SZ /d "$Env:path;$installDir"
}
$pathNow = $installDir
if(Test-RegistryValue -Path "HKCU:\Environment" -Value "Path"){
$pathNow = Get-ItemPropertyValue -Path HKCU:\Environment -Name "Path"
$pathNow = "$pathNow;$installDir"
}
Write-Output $pathNow
New-ItemProperty -Path "HKCU:\Environment" -Name "Path" -Value "$pathNow" -PropertyType String -Force
setx ERGO_PATH "$installDir"