-
Notifications
You must be signed in to change notification settings - Fork 37
/
install.sh
executable file
·68 lines (58 loc) · 1.8 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
#!/bin/sh
# Copyright 2019 the Deno authors. All rights reserved. MIT license.
# Copyright 2022 justjavac. 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 Dvm (see: https://github.com/justjavac/dvm#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 x86_64") target="x86_64-unknown-linux-gnu" ;;
"Linux aarch64") target="aarch64-unknown-linux-gnu.zip" ;;
*) echo "Unsupported OS + CPU combination: $(uname -sm)"; exit 1 ;;
esac
fi
dvm_uri="https://cdn.jsdelivr.net/gh/justjavac/dvm_releases@main/dvm-${target}.zip"
dvm_dir="${DVM_DIR:-$HOME/.dvm}"
dvm_bin_dir="$dvm_dir/bin"
exe="$dvm_bin_dir/dvm"
if [ ! -d "$dvm_bin_dir" ]; then
mkdir -p "$dvm_bin_dir"
fi
if [ "$1" = "" ]; then
cd "$dvm_bin_dir"
curl --fail --location --progress-bar -k --output "$exe.zip" "$dvm_uri"
unzip -o "$exe.zip"
rm "$exe.zip"
else
echo "Install path override detected: $1"
if [ ! -f "$1" ]; then
echo "File does not exist: $1"
exit 1
fi
cp "$1" "$exe"
fi
cd "$dvm_bin_dir"
chmod +x "$exe"
case $SHELL in
/bin/zsh) shell_profile=".zshrc" ;;
*) shell_profile=".bash_profile" ;;
esac
if [ ! $DVM_DIR ];then
EXPORT_DVM_DIR="export DVM_DIR=\"$dvm_dir\""
EXPORT_PATH="export PATH=\"\$DVM_DIR/bin:\$PATH\""
command printf "\\n$EXPORT_DVM_DIR\\n$EXPORT_PATH\\n" >> "$HOME/$shell_profile"
fi
echo "Dvm was installed successfully to $exe"
if command -v dvm >/dev/null; then
command dvm doctor
echo "Run 'dvm --help' to get started."
else
echo "Reopen your shell, or run 'source $HOME/$shell_profile' to get started"
fi