-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathsetup-dashboard.sh
More file actions
executable file
·130 lines (115 loc) · 3.76 KB
/
setup-dashboard.sh
File metadata and controls
executable file
·130 lines (115 loc) · 3.76 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
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
#!/usr/bin/env bash
set -euo pipefail
# Dashboard setup: install Node.js 18+ and frontend dependencies.
# Usage:
# ./setup-dashboard.sh
# Env:
# NODE_INSTALL_METHOD=auto|apt|nvm (default: auto)
# SKIP_NODE_INSTALL=1 to skip installing Node.js
# SKIP_NPM_INSTALL=1 to skip running npm install
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
APP_DIR="${ROOT_DIR}/dashboard/web"
NODE_MIN_MAJOR=18
NODE_INSTALL_METHOD="${NODE_INSTALL_METHOD:-auto}"
echo "AI Performance Engineering Dashboard Setup"
echo "=========================================="
get_node_major() {
if ! command -v node >/dev/null 2>&1; then
echo ""
return 0
fi
node -v | sed 's/^v//' | cut -d. -f1
}
install_node_apt() {
if ! command -v sudo >/dev/null 2>&1; then
echo "[error] sudo is required to install Node.js via apt." >&2
return 1
fi
if ! command -v apt-get >/dev/null 2>&1; then
echo "[error] apt-get not found. Cannot install Node.js via apt." >&2
return 1
fi
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "${ID:-}" != "ubuntu" ] && [ "${ID:-}" != "debian" ]; then
echo "[warn] Detected ${ID:-unknown}; apt packages may not provide Node.js ${NODE_MIN_MAJOR}+." >&2
fi
fi
echo "[setup] Installing Node.js via apt..."
sudo apt-get update
sudo apt-get install -y nodejs npm
}
install_node_nvm() {
if ! command -v curl >/dev/null 2>&1; then
if command -v apt-get >/dev/null 2>&1 && command -v sudo >/dev/null 2>&1; then
echo "[setup] Installing curl..."
sudo apt-get update
sudo apt-get install -y curl
else
echo "[error] curl not found. Install curl to bootstrap nvm." >&2
return 1
fi
fi
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
if [ ! -s "${NVM_DIR}/nvm.sh" ]; then
echo "[setup] Installing nvm..."
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
fi
# shellcheck disable=SC1090
. "${NVM_DIR}/nvm.sh"
echo "[setup] Installing Node.js ${NODE_MIN_MAJOR} via nvm..."
nvm install "${NODE_MIN_MAJOR}"
nvm alias default "${NODE_MIN_MAJOR}"
nvm use "${NODE_MIN_MAJOR}" >/dev/null
}
node_major="$(get_node_major)"
if [ -n "${node_major}" ] && [ "${node_major}" -ge "${NODE_MIN_MAJOR}" ]; then
echo "[ok] Node.js ${node_major} detected"
else
if [ "${SKIP_NODE_INSTALL:-0}" -eq 1 ]; then
echo "[warn] Node.js ${NODE_MIN_MAJOR}+ required. Install manually or rerun without SKIP_NODE_INSTALL=1." >&2
exit 1
fi
case "${NODE_INSTALL_METHOD}" in
apt)
install_node_apt || exit 1
;;
nvm)
install_node_nvm || exit 1
;;
auto)
if command -v apt-get >/dev/null 2>&1; then
install_node_apt || true
fi
node_major="$(get_node_major)"
if [ -z "${node_major}" ] || [ "${node_major}" -lt "${NODE_MIN_MAJOR}" ]; then
echo "[info] apt did not provide Node.js ${NODE_MIN_MAJOR}+; switching to nvm." >&2
install_node_nvm || exit 1
fi
;;
*)
echo "[error] Unknown NODE_INSTALL_METHOD=${NODE_INSTALL_METHOD}. Use auto, apt, or nvm." >&2
exit 1
;;
esac
fi
node_major="$(get_node_major)"
if [ -z "${node_major}" ] || [ "${node_major}" -lt "${NODE_MIN_MAJOR}" ]; then
echo "[error] Node.js ${NODE_MIN_MAJOR}+ not available after install. Please install manually." >&2
exit 1
fi
if ! command -v npm >/dev/null 2>&1; then
echo "[error] npm not found after Node.js install. Please install npm manually." >&2
exit 1
fi
if [ "${SKIP_NPM_INSTALL:-0}" -eq 1 ]; then
echo "[ok] Skipping npm install (SKIP_NPM_INSTALL=1)"
exit 0
fi
if [ ! -d "${APP_DIR}" ]; then
echo "[error] Dashboard app directory not found: ${APP_DIR}" >&2
exit 1
fi
echo "[setup] Installing dashboard npm dependencies..."
(cd "${APP_DIR}" && npm install)
echo "[ok] Dashboard dependencies installed."