-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev_bootstrap.sh
More file actions
324 lines (284 loc) · 8.39 KB
/
dev_bootstrap.sh
File metadata and controls
324 lines (284 loc) · 8.39 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
#!/usr/bin/env bash
# ====================================================================
# Professional Dev Environment Bootstrap Script (with colors & progress)
# Supports: Ubuntu/Debian/macOS
# Features:
# - Installs Python, Git, pipx, and essential CLI tools
# - Configures Git and SSH for GitHub
# - Adds virtualenvwrapper-style aliases (mkvirtualenv, workon)
# - Adds mkproject automation (create folder + git + venv)
# - Installs global Python tools via pipx (poetry, black, pre-commit)
# - Installs terminal productivity tools (fzf, ripgrep, bat, eza)
# - Fully idempotent
# - Shows clear progress messages with colors
# ====================================================================
set -e # Exit on error
# -----------------------------
# Color codes
# -----------------------------
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
BLUE="\033[0;34m"
NC="\033[0m" # No color
echo -e "${BLUE}===== Starting Professional Dev Environment Setup =====${NC}"
# -----------------------------
# 1. Detect OS
# -----------------------------
OS="$(uname)"
DISTRO=""
if [[ "$OS" == "Linux" ]]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
fi
elif [[ "$OS" == "Darwin" ]]; then
DISTRO="macos"
else
echo -e "${RED}Unsupported OS: $OS${NC}"
exit 1
fi
echo -e "${GREEN}Detected OS: $DISTRO${NC}"
# -----------------------------
# 2. Helper Functions
# -----------------------------
command_exists() {
command -v "$1" >/dev/null 2>&1
}
info() {
echo -e "${BLUE}[INFO] $1${NC}"
}
success() {
echo -e "${GREEN}[OK] $1${NC}"
}
warning() {
echo -e "${YELLOW}[SKIP] $1${NC}"
}
error() {
echo -e "${RED}[ERROR] $1${NC}"
}
# -----------------------------
# 3. Install system packages
# -----------------------------
install_linux_packages() {
info "Installing base packages for Linux..."
case "$DISTRO" in
ubuntu|debian)
sudo apt update
sudo apt install -y python3-full python3-venv python3-pip git curl || true
;;
fedora)
sudo dnf install -y python3 python3-pip python3-virtualenv git curl || true
;;
arch)
sudo pacman -Sy --noconfirm python python-pip git curl || true
;;
*)
error "Unsupported Linux distro."
exit 1
;;
esac
success "Base packages installed/skipped as needed."
}
install_macos_packages() {
info "Installing base packages for macOS..."
if ! command_exists brew; then
info "Homebrew not found. Installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
success "Homebrew installed."
else
warning "Homebrew already installed. Skipping."
fi
brew update
brew install python git curl || true
success "Base packages installed/skipped as needed."
}
# -----------------------------
# 4. Install pipx
# -----------------------------
install_pipx() {
if ! command_exists pipx; then
info "Installing pipx..."
python3 -m pip install --user pipx
pipx ensurepath
success "pipx installed."
else
warning "pipx already installed. Skipping."
fi
}
# -----------------------------
# 5. Configure Git
# -----------------------------
setup_git() {
info "Configuring Git..."
current_name=$(git config --global user.name || echo "")
current_email=$(git config --global user.email || echo "")
if [ -z "$current_name" ]; then
read -p "Enter your Git username: " GIT_NAME
git config --global user.name "$GIT_NAME"
success "Git username configured."
else
warning "Git username already set to '$current_name'."
fi
if [ -z "$current_email" ]; then
read -p "Enter your Git email: " GIT_EMAIL
git config --global user.email "$GIT_EMAIL"
success "Git email configured."
else
warning "Git email already set to '$current_email'."
fi
}
# -----------------------------
# 6. Setup SSH for GitHub
# -----------------------------
setup_ssh() {
info "Setting up SSH key for GitHub..."
mkdir -p ~/.ssh
chmod 700 ~/.ssh
if [ ! -f "$HOME/.ssh/id_ed25519" ]; then
ssh-keygen -t ed25519 -C "$(git config --global user.email)" -f "$HOME/.ssh/id_ed25519" -N ""
success "SSH key generated."
else
warning "SSH key already exists. Skipping generation."
fi
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
echo ""
echo -e "${BLUE}Copy this key to GitHub if not already done:${NC}"
echo "https://github.com/settings/keys"
cat ~/.ssh/id_ed25519.pub
echo ""
read -p "Press ENTER after adding key to GitHub..."
ssh -T git@github.com || warning "GitHub authentication may not be confirmed yet."
}
# -----------------------------
# 7. Virtualenvwrapper-style functions
# -----------------------------
setup_virtualenvwrapper() {
info "Adding virtualenvwrapper-style functions..."
RC_FILE="$HOME/.bashrc"
[ "$SHELL" == */zsh ] && RC_FILE="$HOME/.zshrc"
if grep -q "Modern virtualenvwrapper-style" "$RC_FILE"; then
warning "Virtualenvwrapper functions already present. Skipping."
else
cat >> "$RC_FILE" << 'EOF'
# ===== Modern virtualenvwrapper-style =====
export WORKON_HOME="$HOME/.virtualenvs"
mkdir -p "$WORKON_HOME"
mkvirtualenv() {
if [ -z "$1" ]; then
echo "Usage: mkvirtualenv <envname>"
return 1
fi
python3 -m venv "$WORKON_HOME/$1"
source "$WORKON_HOME/$1/bin/activate"
}
workon() {
if [ -z "$1" ]; then
echo "Usage: workon <envname>"
return 1
fi
if [ -d "$WORKON_HOME/$1" ]; then
source "$WORKON_HOME/$1/bin/activate"
else
echo "Environment '$1' does not exist."
fi
}
rmvirtualenv() {
if [ -z "$1" ]; then
echo "Usage: rmvirtualenv <envname>"
return 1
fi
rm -rf "$WORKON_HOME/$1"
echo "Environment '$1' removed."
}
lsvirtualenv() {
ls "$WORKON_HOME"
}
mkproject() {
if [ -z "$1" ]; then
echo "Usage: mkproject <projectname>"
return 1
fi
mkdir -p "$1"
cd "$1" || return
git init
mkvirtualenv "$1"
touch .gitignore
echo ".venv/" >> .gitignore
git add .
git commit -m "Initial commit"
}
EOF
success "Virtualenvwrapper functions added to $RC_FILE"
fi
}
# -----------------------------
# 8. Install Python CLI tools via pipx
# -----------------------------
install_python_tools() {
declare -a tools=("poetry" "black" "pre-commit")
for tool in "${tools[@]}"; do
if ! pipx list | grep -q "$tool"; then
info "Installing $tool via pipx..."
pipx install "$tool"
success "$tool installed."
else
warning "$tool already installed via pipx. Skipping."
fi
done
}
# -----------------------------
# 9. Install terminal productivity tools
# -----------------------------
install_terminal_tools() {
info "Installing terminal productivity tools..."
if [[ "$DISTRO" == "macos" ]]; then
brew install fzf ripgrep bat eza || true
else
case "$DISTRO" in
ubuntu|debian)
sudo apt install -y fzf ripgrep bat eza || true
;;
fedora)
sudo dnf install -y fzf ripgrep bat eza || true
;;
arch)
sudo pacman -Sy --noconfirm fzf ripgrep bat eza || true
;;
esac
fi
success "Terminal tools installed/skipped as needed."
}
# -----------------------------
# 10. Execute all steps
# -----------------------------
info "Step 1: Install base packages"
if [[ "$DISTRO" == "macos" ]]; then
install_macos_packages
else
install_linux_packages
fi
info "Step 2: Install pipx"
install_pipx
info "Step 3: Configure Git"
setup_git
info "Step 4: Setup SSH key for GitHub"
setup_ssh
info "Step 5: Add virtualenvwrapper-style functions"
setup_virtualenvwrapper
info "Step 6: Install Python CLI tools via pipx"
install_python_tools
info "Step 7: Install terminal productivity tools"
install_terminal_tools
echo ""
success "===== DEV SETUP COMPLETE! ====="
echo "Restart your terminal or run: source ~/.bashrc (or ~/.zshrc)"
echo ""
echo "You can now use:"
echo " mkvirtualenv <env>"
echo " workon <env>"
echo " lsvirtualenv"
echo " rmvirtualenv <env>"
echo " mkproject <project>"
echo " pipx install <tool> (for global Python CLIs)"