-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-tools.sh
More file actions
executable file
·350 lines (309 loc) · 12.6 KB
/
Copy pathsetup-tools.sh
File metadata and controls
executable file
·350 lines (309 loc) · 12.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/bash
set -e
echo "=== mni Development Tools Installation ==="
# Base directories - works from any location
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MNI_ROOT="$(dirname "$SCRIPT_DIR")"
BACKEND_DIR="${MNI_ROOT}/mni-backend"
INSTALL_DIR="$HOME/.local/bin"
LOCAL_SHARE_DIR="$HOME/.local/share"
# Create backend directory if it doesn't exist
mkdir -p "$BACKEND_DIR"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_status() { echo -e "${GREEN}[INFO]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
# Check if running as root
if [ "$EUID" -eq 0 ]; then
print_error "Please do not run as root"
exit 1
fi
# Create installation directory
mkdir -p "$INSTALL_DIR"
# Install build-essential (includes make, gcc, etc.)
install_build_essential() {
if command -v make >/dev/null 2>&1; then
print_status "make is already installed"
else
print_status "Installing build-essential..."
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update && sudo apt-get install -y build-essential
elif command -v yum >/dev/null 2>&1; then
sudo yum groupinstall -y "Development Tools"
elif command -v dnf >/dev/null 2>&1; then
sudo dnf groupinstall -y "Development Tools"
elif command -v pacman >/dev/null 2>&1; then
sudo pacman -S --noconfirm base-devel
else
print_error "Cannot install build-essential - unknown package manager"
return 1
fi
print_status "build-essential installed successfully"
fi
}
# Install Go 1.24.2
install_go() {
if command -v go >/dev/null 2>&1 && go version | grep -q "1.24"; then
print_status "Go 1.24.x is already installed"
else
print_status "Installing Go 1.24.2..."
wget -q --show-progress https://go.dev/dl/go1.24.2.linux-amd64.tar.gz -O /tmp/go.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf /tmp/go.tar.gz
rm /tmp/go.tar.gz
# Add to PATH
if ! grep -q "/usr/local/go/bin" ~/.bashrc; then
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
fi
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
print_status "Go installed successfully"
fi
}
# Install Node.js for frontend development
install_node() {
local node_version="22.12.0"
local config_file="${SCRIPT_DIR}/components.yaml"
if [ -f "$config_file" ] && command -v yq >/dev/null 2>&1; then
node_version=$(yq eval '.build_tools.node_version // "22.12.0"' "$config_file")
fi
if command -v node >/dev/null 2>&1; then
local node_major
node_major=$(node --version | sed -E 's/^v([0-9]+).*/\1/')
if [ "$node_major" -ge 22 ]; then
print_status "Node.js $(node --version) is already installed"
return
fi
fi
print_status "Installing Node.js ${node_version}..."
local node_archive="node-v${node_version}-linux-x64.tar.xz"
local node_dir="${LOCAL_SHARE_DIR}/node-v${node_version}-linux-x64"
mkdir -p "$LOCAL_SHARE_DIR"
wget -q --show-progress "https://nodejs.org/dist/v${node_version}/${node_archive}" -O "/tmp/${node_archive}"
tar -xJf "/tmp/${node_archive}" -C "$LOCAL_SHARE_DIR"
rm "/tmp/${node_archive}"
ln -sf "${node_dir}/bin/node" "$INSTALL_DIR/node"
ln -sf "${node_dir}/bin/npm" "$INSTALL_DIR/npm"
ln -sf "${node_dir}/bin/npx" "$INSTALL_DIR/npx"
if [ -x "${node_dir}/bin/corepack" ]; then
ln -sf "${node_dir}/bin/corepack" "$INSTALL_DIR/corepack"
fi
print_status "Node.js ${node_version} installed successfully"
}
# Install Docker
install_docker() {
if command -v docker >/dev/null 2>&1; then
print_status "Docker is already installed"
# Check if user is in docker group
if ! groups | grep -q docker; then
print_warning "Adding user to docker group..."
sudo usermod -aG docker $USER
print_warning "Please log out and back in for group changes to take effect"
fi
else
print_status "Installing Docker..."
curl -fsSL https://get.docker.com | sudo sh
sudo usermod -aG docker $USER
print_warning "Please log out and back in for Docker group changes to take effect"
fi
}
# Install mnibuilder (from private repo, requires gh CLI)
install_mnibuilder() {
if command -v mnibuilder >/dev/null 2>&1; then
print_status "mnibuilder is already installed"
else
# Get version from components.yaml if available
CONFIG_FILE="${SCRIPT_DIR}/components.yaml"
if [ -f "$CONFIG_FILE" ] && command -v yq >/dev/null 2>&1; then
MNIBUILDER_VERSION=$(yq eval '.build_tools.mnibuilder_version' "$CONFIG_FILE")
elif [ -f "$CONFIG_FILE" ] && command -v python3 >/dev/null 2>&1; then
MNIBUILDER_VERSION=$(python3 -c "import yaml; print(yaml.safe_load(open('$CONFIG_FILE'))['build_tools']['mnibuilder_version'])" 2>/dev/null)
fi
# Default version if not specified
MNIBUILDER_VERSION=${MNIBUILDER_VERSION:-"v0.0.3"}
print_status "Installing mnibuilder ${MNIBUILDER_VERSION}..."
# mnibuilder is in a private repo, need gh CLI
if command -v gh >/dev/null 2>&1; then
# Check gh auth status
if ! gh auth status &>/dev/null; then
print_warning "GitHub CLI not authenticated. Please login first:"
gh auth login
fi
# Download to /tmp like other tools
gh release download "${MNIBUILDER_VERSION}" \
--repo mNi-Cloud/mnibuilder \
--pattern "mnibuilder_Linux_x86_64.tar.gz" \
--dir /tmp \
--clobber || {
print_error "Failed to download mnibuilder ${MNIBUILDER_VERSION}"
print_warning "Make sure you have access to the mNi-Cloud/mnibuilder repository"
return 1
}
# Extract and install
tar -xzf /tmp/mnibuilder_Linux_x86_64.tar.gz -C /tmp
mv /tmp/mnibuilder "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/mnibuilder"
rm /tmp/mnibuilder_Linux_x86_64.tar.gz # Clean up
print_status "mnibuilder ${MNIBUILDER_VERSION} installed successfully"
else
print_error "GitHub CLI (gh) is required to download mnibuilder from private repo"
print_warning "Please install gh first or run this script later after gh is installed"
return 1
fi
fi
}
# Install aqua
install_aqua() {
if command -v aqua >/dev/null 2>&1; then
print_status "aqua is already installed"
else
print_status "Installing aqua..."
AQUA_VERSION="2.38.0"
wget -q --show-progress "https://github.com/aquaproj/aqua/releases/download/v${AQUA_VERSION}/aqua_linux_amd64.tar.gz" -O /tmp/aqua.tar.gz
tar -xzf /tmp/aqua.tar.gz -C /tmp
mv /tmp/aqua "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/aqua"
rm /tmp/aqua.tar.gz
# Add aqua path to bashrc
if ! grep -q "AQUA_ROOT_DIR" ~/.bashrc; then
echo 'export AQUA_ROOT_DIR=$HOME/.local/share/aquaproj-aqua' >> ~/.bashrc
echo 'export PATH=$AQUA_ROOT_DIR/bin:$PATH' >> ~/.bashrc
fi
export AQUA_ROOT_DIR=$HOME/.local/share/aquaproj-aqua
export PATH=$AQUA_ROOT_DIR/bin:$PATH
print_status "aqua installed successfully"
fi
}
# Install direnv
install_direnv() {
if command -v direnv >/dev/null 2>&1; then
print_status "direnv is already installed"
else
print_status "Installing direnv..."
DIRENV_VERSION="2.35.0"
wget -q --show-progress "https://github.com/direnv/direnv/releases/download/v${DIRENV_VERSION}/direnv.linux-amd64" -O "$INSTALL_DIR/direnv"
chmod +x "$INSTALL_DIR/direnv"
# Add direnv hook to bashrc
if ! grep -q "direnv hook bash" ~/.bashrc; then
echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
fi
print_status "direnv installed successfully"
fi
}
# Install tmux
install_tmux() {
if command -v tmux >/dev/null 2>&1; then
print_status "tmux is already installed"
else
print_status "Installing tmux..."
# Try package manager first
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update && sudo apt-get install -y tmux
elif command -v yum >/dev/null 2>&1; then
sudo yum install -y tmux
elif command -v pacman >/dev/null 2>&1; then
sudo pacman -S --noconfirm tmux
else
# Fallback to binary
print_warning "Installing tmux as AppImage..."
wget -q --show-progress "https://github.com/nelsonenzo/tmux-appimage/releases/download/v3.5a/tmux-3.5a.AppImage" -O "$INSTALL_DIR/tmux"
chmod +x "$INSTALL_DIR/tmux"
fi
print_status "tmux installed successfully"
fi
}
# Install yq for YAML processing
install_yq() {
if command -v yq >/dev/null 2>&1; then
print_status "yq is already installed"
else
print_status "Installing yq..."
wget -q --show-progress "https://github.com/mikefarah/yq/releases/download/v4.35.2/yq_linux_amd64" -O "$INSTALL_DIR/yq"
chmod +x "$INSTALL_DIR/yq"
print_status "yq installed successfully"
fi
}
# Install Tilt (will be managed by aqua, but install as fallback)
install_tilt() {
if command -v tilt >/dev/null 2>&1; then
print_status "Tilt is already installed"
else
print_status "Installing Tilt..."
curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | bash
print_status "Tilt installed successfully"
fi
}
# Install GitHub CLI
install_gh() {
if command -v gh >/dev/null 2>&1; then
print_status "GitHub CLI is already installed"
else
print_status "Installing GitHub CLI..."
# Download latest release
GH_VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
if [ -z "$GH_VERSION" ]; then
GH_VERSION="2.45.0" # Fallback version
fi
wget -q --show-progress "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz" -O /tmp/gh.tar.gz
tar -xzf /tmp/gh.tar.gz -C /tmp
mv /tmp/gh_${GH_VERSION}_linux_amd64/bin/gh "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/gh"
rm -rf /tmp/gh.tar.gz /tmp/gh_${GH_VERSION}_linux_amd64
print_status "GitHub CLI installed successfully"
fi
}
# Add local bin to PATH
setup_path() {
if ! grep -q "$INSTALL_DIR" ~/.bashrc; then
echo "export PATH=$INSTALL_DIR:\$PATH" >> ~/.bashrc
fi
export PATH=$INSTALL_DIR:$PATH
}
# Main installation
main() {
print_status "Starting installation of development tools..."
# Setup PATH first
setup_path
# Install tools in order
# Install gh first (needed for private repos)
install_gh
install_build_essential # Install make and build tools
install_yq
install_go
install_node
install_docker
install_mnibuilder # Requires gh for private repo access
install_aqua
install_direnv
install_tmux
install_tilt
echo ""
print_status "Installation complete!"
echo ""
echo "=== Installed Tools ==="
make --version 2>/dev/null | head -1 || print_error "make not found"
go version 2>/dev/null || print_error "Go not found"
node --version 2>/dev/null || print_error "Node.js not found"
npm --version 2>/dev/null || print_error "npm not found"
docker --version 2>/dev/null || print_error "Docker not found"
mnibuilder version 2>/dev/null || print_error "mnibuilder not found"
aqua version 2>/dev/null || print_error "aqua not found"
direnv version 2>/dev/null || print_error "direnv not found"
tmux -V 2>/dev/null || print_error "tmux not found"
yq --version 2>/dev/null || print_error "yq not found"
tilt version 2>/dev/null || print_error "Tilt not found"
gh --version 2>/dev/null || print_error "GitHub CLI not found"
echo ""
print_warning "IMPORTANT: Run 'source ~/.bashrc' to update your PATH"
print_warning "If you were added to docker group, log out and back in"
echo ""
print_status "Next step: Run './setup-env.sh' to configure environment"
}
main "$@"