-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·96 lines (82 loc) · 2.52 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·96 lines (82 loc) · 2.52 KB
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
#!/bin/bash
set -e # exit on errors
set -o pipefail # exit on pipe failure
set -u # exit on unset variables
base_dir="$HOME/.nnvm"
cmds_dir="$base_dir/cmds"
cmd_list="cmd default help install list nuke run uninstall unuse update update_versions use resolve_version"
NUKE_NODE=${NUKE_NODE:-0}
ensure_dir() {
if [ ! -d "$1" ]; then
mkdir -p "$1"
echo "Created directory $1"
fi
}
remove_which() {
remove_cmd=$1
echo "Removing previously installed $remove_cmd..."
while true; do
if remove_path=$(which "$remove_cmd" 2>/dev/null); then
echo "Deleting $remove_path"
rm "$remove_path"
else
echo "$remove_cmd removed."
break
fi
done
}
if [ "$NUKE_NODE" -eq 1 ]; then
echo Optional node uninstall requested, removing any existing node installations...
remove_which node
remove_which npm
remove_which npx
fi
# Detect setup method, local or github:
if [[ -t 0 ]] && [[ -d "cmds" ]]; then
# if standard input is a terminal and the cmds dir exists, use local install
echo "Performing local install."
file_source="local"
else
# likely invoked via curl so default to the github download method
file_source="github"
fi
# ensure the base dir exists:
ensure_dir "$base_dir"
# clear out cmds dir, if it exists:
if [ -d "$cmds_dir" ]; then
rm -rf "$cmds_dir" > /dev/null 2>&1
fi
ensure_dir "$cmds_dir"
# copy specific nnvm command scripts to local $cmds_dir:
for cmd_name in $cmd_list
do
file_name="$cmd_name.sh"
if [ "$file_source" = "local" ]; then
echo "Copying file from local: ./cmds/$file_name"
cp "./cmds/$file_name" "$cmds_dir/$file_name"
elif [ "$file_source" = "github" ]; then
# download the file:
echo "Downloading: https://raw.githubusercontent.com/pkg-mgr/nnvm/main/cmds/$file_name"
# disable cache, fail on 404, silence progress (but not errors) and save locally:
curl -H 'Cache-Control: no-cache' -fsS -o "$cmds_dir/$file_name" "https://raw.githubusercontent.com/pkg-mgr/nnvm/main/cmds/$file_name"
else
echo "Unknown file source."
exit 1
fi
# make it executable:
chmod +x "$cmds_dir/$file_name"
done
if [ "$file_source" = "local" ]; then
current_dir=$(dirname "$0")
"$current_dir/cmds/update_versions.sh"
else
"$base_dir/cmds/update_versions.sh"
fi
echo "Installed nnvm cmds: $cmd_list"
echo "Installing scripts in bin folder."
cp "$cmds_dir/cmd.sh" "/usr/local/bin/nnvm"
cp "$cmds_dir/run.sh" "/usr/local/bin/node"
cp "$cmds_dir/run.sh" "/usr/local/bin/npm"
cp "$cmds_dir/run.sh" "/usr/local/bin/npx"
nnvm update_versions
echo Setup completed.