-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-deno.cmd
188 lines (156 loc) · 5.36 KB
/
install-deno.cmd
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env -S bash # > NUL 2>&1 || echo off && goto init:
function shh() { return; } ; shh \\<<shh
## THIS IS THE START OF THE POWERSHELL SCRIPT #################################
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
# TODO(everyone): Keep this script simple and easily auditable.
$ProgressPreference='SilentlyContinue'
$ErrorActionPreference = 'Stop'
if ($v) {
$Version = "v${v}"
}
if ($args.Length -eq 1) {
$Version = $args.Get(0)
}
if (-not $Version) {
$version = ((iwr https://api.github.com/repos/denoland/deno/releases/latest).Content | convertfrom-json).name
}
$DenoInstall = $env:DENO_INSTALL
$BinDir = if ($DenoInstall) {
"$DenoInstall\bin"
} else {
"$Home\.deno\bin"
}
$DenoZip = "$BinDir\deno.zip"
$DenoExe = "$BinDir\deno.exe"
$Target = 'x86_64-pc-windows-msvc'
# GitHub requires TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$DenoUri = "https://github.com/denoland/deno/releases/download/${Version}/deno-${Target}.zip"
if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}
# check if it's here already.
if( test-path $DenoExe ) {
$installed = [System.Version] (((& $DenoExe --version)[0]) -split "deno\s*([\d\.]+)")[1]
$latest = [System.Version] $version.split('v')[1]
if( $installed -ge $latest ) {
$skip = $true
}
}
if(-not $skip) {
curl.exe -Lo $DenoZip $DenoUri
tar.exe xf $DenoZip -C $BinDir
Remove-Item $DenoZip
}
$User = [EnvironmentVariableTarget]::User
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
if (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) {
[Environment]::SetEnvironmentVariable('Path', "$Path;$BinDir", $User)
}
if(!(get-command -ea 0 deno) ) {
$Env:Path += ";$BinDir"
}
Write-Output "Deno was installed successfully to $DenoExe"
Write-Output "Run 'deno --help' to get started"
if( $ENV:DENO_POSTSCRIPT -ne $null ) {
# dump the environment into the file
$content = @"
echo off
set PATH=$ENV:PATH
set DENO_INSTALL=$ENV:DENO_INSTALL
"@
set-content -Path $ENV:DENO_POSTSCRIPT -value $content
}
return;
## THIS IS THE END OF THE POWERSHELL SCRIPT ###################################
<#
shh
## THIS IS THE START OF THE POSIX SCRIPT ######################################
# check to see if we've been dot-sourced
sourced=0
if [ -n "$ZSH_EVAL_CONTEXT" ]; then
case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
elif [ -n "$BASH_VERSION" ]; then
(return 0 2>/dev/null) && sourced=1
else # All other shells: examine $0 for known shell binary filenames
# Detects `sh` and `dash`; add additional shell filenames as needed.
case ${0##*/} in sh|dash) sourced=1;; esac
fi
if [ $sourced -eq 0 ]; then
echo 'This script is expected to be dot-sourced'
echo ''
echo "You should instead run '. $(basename $0)'"
exit
fi
# Copyright 2019 the Deno authors. All rights reserved. MIT license.
# TODO(everyone): Keep this script simple and easily auditable.
set -e
if ! command -v unzip >/dev/null; then
echo "Error: unzip is required to install Deno (see: https://github.com/denoland/deno_install#unzip-is-required)." 1>&2
exit 1
fi
if [ "$OS" = "Windows_NT" ]; then
target="x86_64-pc-windows-msvc"
else
case $(uname -sm) in
"Darwin x86_64") target="x86_64-apple-darwin" ;;
"Darwin arm64") target="aarch64-apple-darwin" ;;
"Linux aarch64")
echo "Error: Official Deno builds for Linux aarch64 are not available. (https://github.com/denoland/deno/issues/1846)" 1>&2
exit 1
;;
*) target="x86_64-unknown-linux-gnu" ;;
esac
fi
if [ $# -eq 0 ]; then
deno_uri="https://github.com/denoland/deno/releases/latest/download/deno-${target}.zip"
else
deno_uri="https://github.com/denoland/deno/releases/download/${1}/deno-${target}.zip"
fi
deno_install="${DENO_INSTALL:-$HOME/.deno}"
bin_dir="$deno_install/bin"
exe="$bin_dir/deno"
if [ ! -d "$bin_dir" ]; then
mkdir -p "$bin_dir"
fi
curl --fail --location --progress-bar --output "$exe.zip" "$deno_uri"
unzip -d "$bin_dir" -o "$exe.zip"
chmod +x "$exe"
rm "$exe.zip"
echo "Deno was installed successfully to $exe"
if command -v deno >/dev/null; then
echo "Run 'deno --help' to get started"
else
case $SHELL in
/bin/zsh) shell_profile=".zshrc" ;;
*) shell_profile=".bashrc" ;;
esac
echo "Manually add the directory to your \$HOME/$shell_profile (or similar)"
echo " export DENO_INSTALL=\"$deno_install\""
echo " export PATH=\"\$DENO_INSTALL/bin:\$PATH\""
echo "Run '$exe --help' to get started"
fi
DENO_INSTALL=$deno_install
PATH=$DENO_INSTALL/bin:$PATH
return
## THIS IS THE END OF THE POSIX SCRIPT ########################################
## THIS IS THE START OF THE CMD SCRIPT ########################################
:init
cls
IF "%DENO_INSTALL%"=="" SET DENO_INSTALL=%USERPROFILE%\.deno
SET /A DENO_POSTSCRIPT=%RANDOM% * 32768 + %RANDOM%
SET DENO_POSTSCRIPT=%DENO_INSTALL%\DENO_tmp_%DENO_POSTSCRIPT%.cmd
set POWERSHELL_EXE=
for %%i in (pwsh.exe powershell.exe) do (
if EXIST "%%~$PATH:i" set POWERSHELL_EXE=%%~$PATH:i & goto :gotpwsh
)
:gotpwsh
"%POWERSHELL_EXE%" -noprofile -executionpolicy unrestricted -command "iex (get-content %~dfp0 -raw)#"
:POSTSCRIPT
:: Call the post-invocation script if it is present, then delete it.
:: This allows the invocation to potentially modify the caller's environment (e.g. PATH).
IF NOT EXIST "%DENO_POSTSCRIPT%" GOTO :fin
CALL "%DENO_POSTSCRIPT%"
DEL "%DENO_POSTSCRIPT%"
: THIS IS THE END OF THE CMD SCRIPT ###########################################
:#>