-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathruntime-node.sh
More file actions
71 lines (55 loc) · 1.6 KB
/
runtime-node.sh
File metadata and controls
71 lines (55 loc) · 1.6 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
#!/bin/bash
# Shared embedded Node runtime helpers.
# Canonical embedded Node version used by setup/install unless overridden.
: "${BAUDBOT_RUNTIME_NODE_VERSION_DEFAULT:=22.14.0}"
bb_runtime_node_version() {
echo "${BAUDBOT_RUNTIME_NODE_VERSION:-$BAUDBOT_RUNTIME_NODE_VERSION_DEFAULT}"
}
bb_runtime_node_versioned_dir() {
local home_dir="${1:?home directory required}"
echo "$home_dir/opt/node-v$(bb_runtime_node_version)-linux-x64"
}
bb_runtime_node_bin_dir() {
local home_dir="${1:?home directory required}"
if [ -n "${BAUDBOT_RUNTIME_NODE_BIN_DIR:-}" ]; then
echo "$BAUDBOT_RUNTIME_NODE_BIN_DIR"
return 0
fi
if [ -n "${BAUDBOT_RUNTIME_NODE_DIR:-}" ]; then
echo "$BAUDBOT_RUNTIME_NODE_DIR/bin"
return 0
fi
echo "$home_dir/opt/node/bin"
}
bb_resolve_runtime_node_bin() {
local home_dir="${1:-${HOME:-}}"
local candidate=""
[ -n "$home_dir" ] || return 1
for candidate in \
"${BAUDBOT_RUNTIME_NODE_BIN:-}" \
"$(bb_runtime_node_bin_dir "$home_dir")/node" \
"$(bb_runtime_node_versioned_dir "$home_dir")/bin/node" \
"$home_dir/opt/node-v"*-linux-x64/bin/node; do
[ -n "$candidate" ] || continue
# If the glob didn't expand, skip the literal pattern.
case "$candidate" in
*\**)
continue
;;
esac
if [ -x "$candidate" ]; then
echo "$candidate"
return 0
fi
done
return 1
}
bb_resolve_runtime_node_bin_dir() {
local home_dir="${1:-${HOME:-}}"
local node_bin=""
if node_bin="$(bb_resolve_runtime_node_bin "$home_dir")"; then
dirname "$node_bin"
return 0
fi
bb_runtime_node_bin_dir "$home_dir"
}