-
Notifications
You must be signed in to change notification settings - Fork 182
/
install.sh
executable file
·101 lines (89 loc) · 2.61 KB
/
install.sh
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
#!/bin/sh
# 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 && ! command -v 7z >/dev/null; then
echo "Error: either unzip or 7z is required to install Deno (see: https://github.com/denoland/deno_install#either-unzip-or-7z-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") target="aarch64-unknown-linux-gnu" ;;
*) target="x86_64-unknown-linux-gnu" ;;
esac
fi
print_help_and_exit() {
echo "Setup script for installing deno
Options:
-y, --yes
Skip interactive prompts and accept defaults
--no-modify-path
Don't add deno to the PATH environment variable
-h, --help
Print help
"
echo "Note: Deno was not installed"
exit 0
}
# Simple arg parsing - look for help flag, otherwise
# ignore args starting with '-' and take the first
# positional arg as the deno version to install
for arg in "$@"; do
case "$arg" in
"-h")
print_help_and_exit
;;
"--help")
print_help_and_exit
;;
"-"*) ;;
*)
if [ -z "$deno_version" ]; then
deno_version="$arg"
fi
;;
esac
done
if [ -z "$deno_version" ]; then
deno_version="$(curl -s https://dl.deno.land/release-latest.txt)"
fi
deno_uri="https://dl.deno.land/release/${deno_version}/deno-${target}.zip"
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"
if command -v unzip >/dev/null; then
unzip -d "$bin_dir" -o "$exe.zip"
else
7z x -o"$bin_dir" -y "$exe.zip"
fi
chmod +x "$exe"
rm "$exe.zip"
echo "Deno was installed successfully to $exe"
run_shell_setup() {
$exe run -A --reload jsr:@deno/installer-shell-setup/bundled "$deno_install" "$@"
}
# If stdout is a terminal, see if we can run shell setup script (which includes interactive prompts)
if [ -z "$CI" ] && [ -t 1 ] && $exe eval 'const [major, minor] = Deno.version.deno.split("."); if (major < 2 && minor < 42) Deno.exit(1)'; then
if [ -t 0 ]; then
run_shell_setup "$@"
else
# This script is probably running piped into sh, so we don't have direct access to stdin.
# Instead, explicitly connect /dev/tty to stdin
run_shell_setup "$@" </dev/tty
fi
fi
if command -v deno >/dev/null; then
echo "Run 'deno --help' to get started"
else
echo "Run '$exe --help' to get started"
fi
echo
echo "Stuck? Join our Discord https://discord.gg/deno"