-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall-tooling.sh
More file actions
executable file
·133 lines (102 loc) · 3.66 KB
/
Copy pathinstall-tooling.sh
File metadata and controls
executable file
·133 lines (102 loc) · 3.66 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
131
132
133
#!/usr/bin/env bash
# This script installs the tools used by build-openapi.sh
# and /tools/validator.js
# do not run as root
set -euo pipefail
# source the common.sh script, the -- tells cd and dirname that everything that
# follows is data, not options.
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common.sh"
# fail fast if running as root or with sudo
require_not_root || exit 1
load_nvm() {
echo "⬇️ Checking nvm..."
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
if [ -s "$NVM_DIR/nvm.sh" ]; then
# Installed: load it
. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
fi
if type nvm >/dev/null 2>&1; then
echo "✅ NVM already installed & loaded."
else
echo "⬇️ Installing nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# Load into current shell
. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
# Optional: fail fast if something went wrong
type nvm >/dev/null 2>&1 || { echo "❌ nvm install succeeded but nvm failed to load"; exit 1; }
fi
}
echo "🔧 Starting toolchain setup..."
NODE_VERSION="20.19.0"
if command -v node >/dev/null 2>&1; then
CURRENT_NODE_VERSION="$(node -v | sed 's/^v//')"
else
CURRENT_NODE_VERSION=""
fi
if [ -z "$CURRENT_NODE_VERSION" ] || ! version_ge "$CURRENT_NODE_VERSION" "$NODE_VERSION"; then
load_nvm
echo "⬇️ Installing Node.js $NODE_VERSION..."
nvm install "$NODE_VERSION"
# activate this version and ensure node is on PATH for the rest of the script
nvm use "$NODE_VERSION" >/dev/null
NODE_INST_DIR="$NVM_DIR/versions/node/v$NODE_VERSION"
if [ -d "$NODE_INST_DIR/bin" ]; then
export PATH="$NODE_INST_DIR/bin:$PATH"
hash -r
fi
else
echo "✅ Node.js $CURRENT_NODE_VERSION already satisfies >= $NODE_VERSION"
fi
# final sanity check
command -v node >/dev/null 2>&1 || { echo "❌ node not found after nvm use + PATH patch"; exit 1; }
echo "📦 Node.js version set to $(node -v)"
# --- REDOCLY CLI INSTALL ---
# Runs the CLI via npx; downloads if needed, caches automatically.
if npx -y @redocly/cli --version >/dev/null 2>&1; then
echo "✅ Redocly CLI available via npx."
else
echo "❌ npx failed (Node/npm not available)."
npx -y @redocly/cli --version
exit 1
fi
# --- YQ INSTALL ---
if ! command -v yq &> /dev/null; then
echo "⬇️ Installing yq..."
OS="$(detect_os)" || { echo "❌ Unsupported OS"; exit 1; }
ARCH="$(detect_arch)" || { echo "❌ Unsupported ARCH"; exit 1; }
if [[ "$OS" == "darwin" ]]; then
if ! command -v brew &> /dev/null; then
echo "❌ Homebrew not found. Install brew first."
exit 1
fi
echo "🍺 Installing yq via Homebrew..."
brew install yq
else
# Linux path
VERSION="$(curl -fsSLI -o /dev/null -w '%{url_effective}' \
https://github.com/mikefarah/yq/releases/latest | sed 's|.*/tag/||')"
INSTALL_DIR="$HOME/.local/bin"
echo "📦 Downloading yq ${VERSION} for ${OS}/${ARCH}..."
mkdir -p "$INSTALL_DIR"
curl -fL -o "$INSTALL_DIR/yq" \
"https://github.com/mikefarah/yq/releases/download/${VERSION}/yq_${OS}_${ARCH}"
chmod +x "$INSTALL_DIR/yq"
# --- PATH handling ------------------------------------------------------
# Add to PATH for current shell
if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then
export PATH="$INSTALL_DIR:$PATH"
fi
fi
else
echo "✅ yq already installed."
fi
# --- DONE ---
echo ""
echo "🎉 Toolchain is ready:"
echo "• Node.js: $(node -v)"
echo "• npm: $(npm -v)"
echo "• redocly: $(npx -y @redocly/cli --version)"
echo "• yq: $(yq --version)"