-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
93 lines (75 loc) · 2.12 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
Param (
[Parameter(HelpMessage = 'version tag ie. "v0.20.0"')]
[string]$version = 'latest'
)
# stop on first error
$ErrorActionPreference = "Stop"
function identify_arch() {
switch ($env:PROCESSOR_ARCHITECTURE) {
"AMD64" {
"x86_64"
}
# NOTE: not currently supported
# "ARM64" {
# "aarch64"
# }
default {
$env:PROCESSOR_ARCHITECTURE
}
}
}
function prepend_to_path() {
Param (
[string]$new_path
)
$pathString = [Environment]::GetEnvironmentVariable("Path", "User")
$pathArray = $pathString.Split(';')
# new path not in existing path
if ($pathArray -cnotcontains $new_path) {
[Environment]::SetEnvironmentVariable(
"Path",
$new_path +
[IO.Path]::PathSeparator +
$pathString,
"User"
)
}
}
function hide_item() {
Param (
[string]$path
)
$item = Get-Item $path -Force
if (!($item.Attributes -band "Hidden")) {
$item.Attributes = $item.Attributes -bor "Hidden"
}
}
Write-Output '==> identifying os/arch'
$os = 'windows'
$arch = identify_arch
Write-Output '==> download nk'
# paths
$nk_dir = "${HOME}\.nk"
$bin_directory = "${nk_dir}\bin"
$nk_path = "${bin_directory}\nk.exe"
# create bin directory
[void](New-Item -ItemType Directory -Force -Path $bin_directory)
# hide nk dir
hide_item $nk_dir
# determine nk url
$nk_url = if ($version -ceq 'latest') {
"https://github.com/ciiqr/nk/releases/latest/download/nk-${os}-${arch}.exe"
}
else {
"https://github.com/ciiqr/nk/releases/download/${version}/nk-${os}-${arch}.exe"
}
# download nk binary
(New-Object System.Net.WebClient).Downloadfile($nk_url, $nk_path)
Write-Output '==> prepend to path'
# prepend to path
prepend_to_path -new_path $bin_directory
# TODO: not sure if there's a standard path for this stuff on windows? might just need to tell the user to add it to their powershell profile...
# Write-Output '==> create powershell completions'
# # create completions
# Write-Output '==> create completions'
# & $nk_path completion install