-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall.ps1
More file actions
89 lines (69 loc) · 2.19 KB
/
install.ps1
File metadata and controls
89 lines (69 loc) · 2.19 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env pwsh
$ErrorActionPreference = 'Stop'
$githubUrl = "https://github.com"
$owner = "cask-pkg"
$repoName = "cask.rs"
$exeName = "cask"
$version = ""
if ([Environment]::Is64BitProcess) {
$arch = "x86_64"
} else {
$arch = "x86"
}
$BinDir = "$Home\bin"
$CaskBinDir = "$Home\.cask\bin"
$downloadedTagGz = "$BinDir\${exeName}.tar.gz"
$downloadedExe = "$BinDir\${exeName}.exe"
$fileName = "${exeName}-${arch}-pc-windows-msvc"
# GitHub requires TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ResourceUri = if (!$version) {
"${githubUrl}/${owner}/${repoName}/releases/latest/download/${fileName}.tar.gz"
} else {
"${githubUrl}/${owner}/${repoName}/releases/download/${Version}/${fileName}.tar.gz"
}
if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}
Invoke-WebRequest $ResourceUri -OutFile $downloadedTagGz -UseBasicParsing -ErrorAction Stop
function Check-Command {
param($Command)
$found = $false
try
{
$Command | Out-Null
$found = $true
}
catch [System.Management.Automation.CommandNotFoundException]
{
$found = $false
}
$found
}
if (Check-Command -Command tar) {
Invoke-Expression "tar -xvzf $downloadedTagGz -C $BinDir"
} else {
function Expand-Tar($tarFile, $dest) {
if (-not (Get-Command Expand-7Zip -ErrorAction Ignore)) {
Install-Package -Scope CurrentUser -Force 7Zip4PowerShell > $null
}
Expand-7Zip $tarFile $dest
}
Expand-Tar $downloadedTagGz $BinDir
}
Remove-Item $downloadedTagGz
$User = [EnvironmentVariableTarget]::User
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
# add $HOME\bin to $PATH
if (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) {
[Environment]::SetEnvironmentVariable('Path', "$Path;$BinDir", $User)
$Env:Path += ";$BinDir"
}
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
# add $HOME\.cask\bin to $PATH
if (!(";$Path;".ToLower() -like "*;$CaskBinDir;*".ToLower())) {
[Environment]::SetEnvironmentVariable('Path', "$Path;$CaskBinDir", $User)
$Env:Path += ";$CaskBinDir"
}
Write-Output "${exeName} was installed successfully to $downloadedExe"
Write-Output "Run '${exeName} --help' to get started"