-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
53 lines (41 loc) · 1.58 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
#
# Copyright (c) Aaron Delasy
# Licensed under the MIT License
#
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
function Get-SystemEnv ([string] $Name) {
[Environment]::GetEnvironmentVariable($Name, [EnvironmentVariableTarget]::Machine)
}
function Request-File ([string] $Url, [string] $Path) {
(New-Object -TypeName System.Net.WebClient).DownloadFile($DownloadUrl, $InstallPath)
}
function Set-ExecuteAcl ([string] $Path) {
$Acl = Get-Acl -Path $Path
$AccessRule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList Users, Traverse, Allow
$Acl.SetAccessRule($AccessRule)
Set-Acl -Path $Path -AclObject $Acl
}
function Set-SystemEnv ([string] $Name, [string] $Value) {
[System.Environment]::SetEnvironmentVariable($Name, $Value, [System.EnvironmentVariableTarget]::Machine)
}
function main {
$DownloadUrl = 'https://cdn.thelang.io/cli-core-windows'
$InstallDir = "$env:UserProfile\The"
if (Test-Path -Path "$InstallDir\bin") {
Write-Host 'The CLI is already installed'
return
}
Write-Host 'Installing The CLI...'
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
$InstallDir += "\bin"
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
$InstallPath = "$InstallDir\the.exe"
Request-File -Url $DownloadUrl -Path $InstallPath
Set-ExecuteAcl -Path $InstallPath
Set-SystemEnv -Name Path -Value "$(Get-SystemEnv -Name Path);$InstallDir"
$env:Path += ";$InstallDir"
Write-Host 'Successfully installed The CLI!'
Write-Host ' Type `the -h` to explore available options'
}
main