-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·401 lines (334 loc) · 10.5 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·401 lines (334 loc) · 10.5 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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/bin/bash
# Generic DevContainer Generator
# This script generates a .devcontainer configuration based on your project needs
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
# Function to prompt for input with default value
prompt_with_default() {
local prompt="$1"
local default="$2"
local result
read -p "$(echo -e ${BLUE}?${NC}) $prompt [$default]: " result
echo "${result:-$default}"
}
# Function to prompt yes/no
prompt_yes_no() {
local prompt="$1"
local default="$2"
local result
if [ "$default" = "y" ]; then
read -p "$(echo -e ${BLUE}?${NC}) $prompt [Y/n]: " result
result="${result:-y}"
else
read -p "$(echo -e ${BLUE}?${NC}) $prompt [y/N]: " result
result="${result:-n}"
fi
[[ "$result" =~ ^[Yy]$ ]]
}
# Banner
echo ""
echo -e "${GREEN}╔═══════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Generic DevContainer Generator ║${NC}"
echo -e "${GREEN}╔═══════════════════════════════════════════╗${NC}"
echo ""
# Check if .devcontainer already exists
if [ -d ".devcontainer" ]; then
print_warning ".devcontainer directory already exists!"
if ! prompt_yes_no "Do you want to overwrite it?" "n"; then
print_info "Installation cancelled."
exit 0
fi
rm -rf .devcontainer
fi
# Collect configuration
print_info "Let's configure your development container..."
echo ""
# Base image
print_info "Select base image:"
echo " 1) Ubuntu (latest)"
echo " 2) Debian (latest)"
echo " 3) Alpine (lightweight)"
BASE_CHOICE=$(prompt_with_default "Choose base image" "1")
case $BASE_CHOICE in
1) BASE_IMAGE="ubuntu:latest" ;;
2) BASE_IMAGE="debian:latest" ;;
3) BASE_IMAGE="alpine:latest" ;;
*) BASE_IMAGE="ubuntu:latest" ;;
esac
# Python
INSTALL_PYTHON=false
PYTHON_VERSION=""
if prompt_yes_no "Install Python?" "y"; then
INSTALL_PYTHON=true
PYTHON_VERSION=$(prompt_with_default "Python version (e.g., 3.11, 3.12)" "3.12")
fi
# Node.js
INSTALL_NODE=false
NODE_VERSION=""
if prompt_yes_no "Install Node.js?" "y"; then
INSTALL_NODE=true
NODE_VERSION=$(prompt_with_default "Node.js version (e.g., 18, 20, 22)" "22")
fi
# Go
INSTALL_GO=false
GO_VERSION=""
if prompt_yes_no "Install Go?" "n"; then
INSTALL_GO=true
GO_VERSION=$(prompt_with_default "Go version (e.g., 1.22.0, 1.23.2, 1.24.0)" "1.24.0")
fi
# Git
INSTALL_GIT=true
GIT_NAME=$(prompt_with_default "Git user name" "$(git config --global user.name 2>/dev/null || echo 'Your Name')")
GIT_EMAIL=$(prompt_with_default "Git user email" "$(git config --global user.email 2>/dev/null || echo 'your.email@example.com')")
# Git Credential Manager
INSTALL_GIT_CREDENTIAL_MANAGER=false
if prompt_yes_no "Setup Git credential manager for HTTP authentication?" "n"; then
INSTALL_GIT_CREDENTIAL_MANAGER=true
fi
# Profiling support (perf, etc.)
ENABLE_PROFILING=false
if prompt_yes_no "Enable profiling tools (perf, etc.)? Requires privileged mode" "n"; then
ENABLE_PROFILING=true
fi
# Container name
CONTAINER_NAME=$(prompt_with_default "Container name" "$(basename $(pwd))-devcontainer")
echo ""
print_info "Generating devcontainer configuration..."
# Create .devcontainer directory
mkdir -p .devcontainer
# Generate Dockerfile
cat > .devcontainer/Dockerfile <<EOF
FROM ${BASE_IMAGE}
# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
# Configure apt and install packages
RUN apt-get update && apt-get install -y --no-install-recommends \\
apt-utils \\
dialog \\
ca-certificates \\
curl \\
wget \\
git \\
vim \\
nano \\
build-essential \\
openssh-client \\
gnupg2 \\
iproute2 \\
procps \\
lsof \\
htop \\
net-tools \\
psmisc \\
unzip \\
zip \\
jq \\
zsh
EOF
# Install Starship and configure Zsh
cat >> .devcontainer/Dockerfile <<EOF
# Install fzf for fuzzy history search (Ctrl+R)
RUN git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf \\
&& ~/.fzf/install --all --no-bash --no-fish
# Install Starship and configure Zsh
RUN curl -sS https://starship.rs/install.sh | sh -s -- -y \\
&& echo 'eval "\$(starship init zsh)"' >> ~/.zshrc \\
&& chsh -s \$(which zsh)
EOF
# Add Git Credential Manager installation
if [ "$INSTALL_GIT_CREDENTIAL_MANAGER" = true ]; then
cat >> .devcontainer/Dockerfile <<EOF
# Install Git Credential Manager
RUN apt-get install -y --no-install-recommends \\
libsecret-1-0 \\
libsecret-1-dev \\
libicu74 \\
&& wget -q https://github.com/GitCredentialManager/git-credential-manager/releases/download/v2.6.0/gcm-linux_amd64.2.6.0.deb \\
&& dpkg -i gcm-linux_amd64.2.6.0.deb \\
&& rm gcm-linux_amd64.2.6.0.deb
EOF
fi
# Add Python installation
if [ "$INSTALL_PYTHON" = true ]; then
cat >> .devcontainer/Dockerfile <<EOF
# Install Python ${PYTHON_VERSION}
RUN apt-get -y install --no-install-recommends \\
python${PYTHON_VERSION} \\
python${PYTHON_VERSION}-dev \\
python${PYTHON_VERSION}-venv \\
python3-pip \\
&& update-alternatives --install /usr/bin/python python /usr/bin/python${PYTHON_VERSION} 1 \\
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1 \\
&& python3 -m pip install --break-system-packages --ignore-installed --upgrade pip setuptools wheel
EOF
fi
# Add Node.js installation
if [ "$INSTALL_NODE" = true ]; then
cat >> .devcontainer/Dockerfile <<EOF
# Install Node.js ${NODE_VERSION}
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - \\
&& apt-get install -y nodejs \\
&& npm install -g npm@latest yarn pnpm
EOF
fi
# Add Go installation
if [ "$INSTALL_GO" = true ]; then
cat >> .devcontainer/Dockerfile <<EOF
# Install Go ${GO_VERSION}
RUN GO_VERSION="${GO_VERSION}" \\
&& wget -q "https://go.dev/dl/go\${GO_VERSION}.linux-amd64.tar.gz" \\
&& tar -C /usr/local -xzf "go\${GO_VERSION}.linux-amd64.tar.gz" \\
&& rm "go\${GO_VERSION}.linux-amd64.tar.gz"
ENV PATH="/usr/local/go/bin:\${PATH}"
ENV GOPATH="/go"
ENV PATH="\${GOPATH}/bin:\${PATH}"
EOF
fi
# Finalize Dockerfile
cat >> .devcontainer/Dockerfile <<EOF
# Configure Git
RUN git config --global user.name "${GIT_NAME}" \\
&& git config --global user.email "${GIT_EMAIL}"
EOF
# Add Git credential helper configuration
if [ "$INSTALL_GIT_CREDENTIAL_MANAGER" = true ]; then
cat >> .devcontainer/Dockerfile <<EOF
# Configure Git credential helper
RUN git config --global credential.helper "/usr/local/bin/git-credential-manager" \\
&& git config --global credential.credentialStore "plaintext"
EOF
fi
# Add profiling tools installation
if [ "$ENABLE_PROFILING" = true ]; then
cat >> .devcontainer/Dockerfile <<EOF
# Install profiling tools (perf, etc.)
RUN apt-get update && apt-get install -y --no-install-recommends \\
linux-tools-generic \\
strace \\
gdb \\
&& echo 'kernel.perf_event_paranoid = -1' >> /etc/sysctl.conf
EOF
fi
# Finalize Dockerfile
cat >> .devcontainer/Dockerfile <<EOF
# Clean up
RUN apt-get autoremove -y \\
&& apt-get clean -y \\
&& rm -rf /var/lib/apt/lists/*
# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog
# Set working directory
WORKDIR /workspace
# Run as root user (no permission issues)
EOF
# Generate devcontainer.json
cat > .devcontainer/devcontainer.json <<EOF
{
"name": "${CONTAINER_NAME}",
EOF
# Add profiling configuration
if [ "$ENABLE_PROFILING" = true ]; then
cat >> .devcontainer/devcontainer.json <<EOF
"privileged": true,
"capAdd": ["SYS_ADMIN", "SYS_PTRACE"],
"securityOpt": ["seccomp=unconfined"],
"runArgs": [
"--name", "devcontainer-${CONTAINER_NAME}",
"--pid=host"
],
EOF
else
cat >> .devcontainer/devcontainer.json <<EOF
"runArgs": [
"--name", "devcontainer-${CONTAINER_NAME}"
],
EOF
fi
cat >> .devcontainer/devcontainer.json <<EOF
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
// Configure tool-specific properties
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh"
EOF
# Add Python settings
if [ "$INSTALL_PYTHON" = true ]; then
cat >> .devcontainer/devcontainer.json <<EOF
,
"python.defaultInterpreterPath": "/usr/bin/python${PYTHON_VERSION}",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.provider": "black"
EOF
fi
cat >> .devcontainer/devcontainer.json <<EOF
},
"extensions": [
"ms-vscode.vscode-typescript-next",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
EOF
# Add Python extensions
if [ "$INSTALL_PYTHON" = true ]; then
cat >> .devcontainer/devcontainer.json <<EOF
,
"ms-python.python",
"ms-python.vscode-pylance"
EOF
fi
# Add Go extensions
if [ "$INSTALL_GO" = true ]; then
cat >> .devcontainer/devcontainer.json <<EOF
,
"golang.go"
EOF
fi
cat >> .devcontainer/devcontainer.json <<EOF
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally
"forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created
"postCreateCommand": "echo 'DevContainer ready!'"
EOF
cat >> .devcontainer/devcontainer.json <<EOF
}
EOF
print_success "DevContainer configuration generated!"
echo ""
print_info "Files created:"
echo " - .devcontainer/devcontainer.json"
echo " - .devcontainer/Dockerfile"
echo ""
print_info "Configuration summary:"
echo " - Base image: ${BASE_IMAGE}"
[ "$INSTALL_PYTHON" = true ] && echo " - Python: ${PYTHON_VERSION}"
[ "$INSTALL_NODE" = true ] && echo " - Node.js: ${NODE_VERSION}"
[ "$INSTALL_GO" = true ] && echo " - Go: ${GO_VERSION}"
[ "$ENABLE_PROFILING" = true ] && echo " - Profiling: enabled (privileged mode)"
echo ""
print_success "Done! Open this folder in VS Code and reopen in container."
echo ""