-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.ps1
112 lines (97 loc) · 3.37 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env pwsh
# Copyright (c) 2019 Abhishek Kumar. All rights reserved. MIT license.
$ErrorActionPreference = 'Stop'
if ($args.Length -gt 0) {
$Version = $args.Get(0)
}
if ($PSVersionTable.PSEdition -ne 'Core') {
$IsWindows = $true
$IsMacOS = $false
}
$OS = if ($IsWindows) {
'windows'
} else {
if ($IsMacOS) {
'darwin'
} else {
'linux'
}
}
$ARCH = if ([System.IntPtr]::Size -eq 4) {
"386"
} else {
"amd64"
}
$INSTALLATION_DIR = if ($IsWindows) {
"$Home\.program\suxm"
} else {
"$Home/.program/suxm"
}
Write-Output "Installing the Suxm CLI at `n $INSTALLATION_DIR"
if (Test-Path $INSTALLATION_DIR) {
Write-Output "Removing previous installation"
Remove-Item -path "$INSTALLATION_DIR" -recurse
}
if (!(Test-Path $INSTALLATION_DIR)) {
Write-Output "Creating installation directory"
New-Item $INSTALLATION_DIR -ItemType Directory | Out-Null
}
$ABSOLUTE_FILEPATH = if ($IsWindows) {
"$INSTALLATION_DIR\Suxm.exe"
} else {
"$INSTALLATION_DIR/Suxm"
}
# GitHub requires TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$DOWNLOAD_LINK = if (!$Version) {
$Response = Invoke-WebRequest 'https://github.com/isurfer21/Suxm/releases' -UseBasicParsing
if ($PSVersionTable.PSEdition -eq 'Core') {
$Response.Links |
Where-Object { $_.href -like "/isurfer21/Suxm/releases/download/*/Suxm_${OS}_${ARCH}" } |
ForEach-Object { 'https://github.com' + $_.href } |
Select-Object -First 1
} else {
$HTMLFile = New-Object -Com HTMLFile
if ($HTMLFile.IHTMLDocument2_write) {
$HTMLFile.IHTMLDocument2_write($Response.Content)
} else {
$ResponseBytes = [Text.Encoding]::Unicode.GetBytes($Response.Content)
$HTMLFile.write($ResponseBytes)
}
$HTMLFile.getElementsByTagName('a') |
Where-Object { $_.href -like "about:/isurfer21/Suxm/releases/download/*/Suxm_${OS}_${ARCH}.exe" } |
ForEach-Object { $_.href -replace 'about:', 'https://github.com' } |
Select-Object -First 1
}
} else {
if ($PSVersionTable.PSEdition -eq 'Core') {
"https://github.com/isurfer21/Suxm/releases/download/$Version/Suxm_${OS}_${ARCH}"
} else {
"https://github.com/isurfer21/Suxm/releases/download/$Version/Suxm_${OS}_${ARCH}.exe"
}
}
Write-Output "Suitable build for ${OS} ${ARCH} `n $DOWNLOAD_LINK"
Write-Output "Downloading the installation package"
Invoke-WebRequest $DOWNLOAD_LINK -OutFile $ABSOLUTE_FILEPATH -UseBasicParsing
Write-Output "Making it globally accessible"
if ($IsWindows) {
$User = [EnvironmentVariableTarget]::User
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
if (!(";$Path;".ToLower() -like "*;$INSTALLATION_DIR;*".ToLower())) {
[Environment]::SetEnvironmentVariable('Path', "$Path;$INSTALLATION_DIR", $User)
$Env:Path += ";$INSTALLATION_DIR"
}
Write-Output "Suxm was installed successfully to $ABSOLUTE_FILEPATH"
Write-Output "Run 'suxm --help' to get started"
} else {
chmod +x "$INSTALLATION_DIR/Suxm"
Write-Output "Suxm was installed successfully to $ABSOLUTE_FILEPATH"
if (Get-Command Suxm -ErrorAction SilentlyContinue) {
Write-Output "Run 'suxm --help' to get started"
} else {
Write-Output "Manually add the directory to your `$HOME/.bash_profile (or similar)"
Write-Output " export PATH=`"${INSTALLATION_DIR}:`$PATH`""
Write-Output "Run '$ABSOLUTE_FILEPATH --help' to get started"
}
}
Write-Output "Done!"