-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
385 lines (308 loc) · 10.1 KB
/
setup.sh
File metadata and controls
385 lines (308 loc) · 10.1 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
#!/bin/bash
# Ubuntu Development Environment Setup Script
# Easy to customize and extend
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to prompt user for yes/no
prompt_yes_no() {
local prompt="$1"
local default="${2:-n}"
if [[ "$default" == "y" ]]; then
prompt="$prompt [Y/n]: "
else
prompt="$prompt [y/N]: "
fi
read -p "$prompt" response
response=${response:-$default}
[[ "$response" =~ ^[Yy]$ ]]
}
# Function to install packages with apt
install_apt_packages() {
local packages=("$@")
log_info "Installing apt packages: ${packages[*]}"
for package in "${packages[@]}"; do
if dpkg -l | grep -q "^ii $package "; then
log_warning "$package is already installed"
else
sudo apt install -y "$package"
log_success "Installed $package"
fi
done
}
# Function to install snap packages
install_snap_packages() {
local packages=("$@")
log_info "Installing snap packages: ${packages[*]}"
for package in "${packages[@]}"; do
if snap list | grep -q "^$package "; then
log_warning "$package is already installed"
else
sudo snap install "$package" --classic 2>/dev/null || sudo snap install "$package"
log_success "Installed $package"
fi
done
}
# Function to add PPAs
add_ppa() {
local ppa="$1"
log_info "Adding PPA: $ppa"
sudo add-apt-repository -y "$ppa"
sudo apt update
}
# System update
update_system() {
log_info "Updating system packages..."
sudo apt update && sudo apt upgrade -y
log_success "System updated"
}
# Install basic development tools
install_dev_tools() {
log_info "Installing basic development tools..."
local dev_packages=(
"build-essential"
"git"
"curl"
"wget"
"vim"
"neovim"
"tree"
"htop"
"unzip"
"software-properties-common"
"apt-transport-https"
"ca-certificates"
"gnupg"
"lsb-release"
"jq"
"xclip"
"ffmpeg"
)
install_apt_packages "${dev_packages[@]}"
}
# Install and configure Zsh with Oh My Zsh
setup_zsh() {
log_info "Setting up Zsh..."
# Install zsh
install_apt_packages "zsh"
# Install Oh My Zsh
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
log_info "Installing Oh My Zsh..."
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
log_success "Oh My Zsh installed"
else
log_warning "Oh My Zsh already installed"
fi
# Change default shell to zsh
if [[ "$SHELL" != */zsh ]]; then
log_info "Changing default shell to zsh..."
chsh -s "$(which zsh)"
log_success "Default shell changed to zsh (requires logout/login)"
else
log_warning "Default shell is already zsh"
fi
# Install popular zsh plugins
local zsh_custom="$HOME/.oh-my-zsh/custom"
# zsh-autosuggestions
if [[ ! -d "$zsh_custom/plugins/zsh-autosuggestions" ]]; then
git clone https://github.com/zsh-users/zsh-autosuggestions "$zsh_custom/plugins/zsh-autosuggestions"
fi
# zsh-syntax-highlighting
if [[ ! -d "$zsh_custom/plugins/zsh-syntax-highlighting" ]]; then
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$zsh_custom/plugins/zsh-syntax-highlighting"
fi
log_success "Zsh setup complete"
}
# Install programming languages
install_golang() {
log_info "Installing Go..."
# Get latest Go version
local go_version
go_version=$(curl -s https://api.github.com/repos/golang/go/releases | jq -r '.[0].tag_name' | sed 's/go//')
if command -v go &> /dev/null; then
local current_version
current_version=$(go version | cut -d' ' -f3 | sed 's/go//')
if [[ "$current_version" == "$go_version" ]]; then
log_warning "Go $current_version is already installed"
return
fi
fi
local go_archive="go${go_version}.linux-amd64.tar.gz"
# Download and install Go
wget -q "https://golang.org/dl/$go_archive" -O "/tmp/$go_archive"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "/tmp/$go_archive"
rm "/tmp/$go_archive"
# Add Go to PATH in .bashrc and .zshrc
local go_path_export='export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin'
if ! grep -q "/usr/local/go/bin" "$HOME/.bashrc" 2>/dev/null; then
echo "$go_path_export" >> "$HOME/.bashrc"
fi
if [[ -f "$HOME/.zshrc" ]] && ! grep -q "/usr/local/go/bin" "$HOME/.zshrc"; then
echo "$go_path_export" >> "$HOME/.zshrc"
fi
export PATH=$PATH:/usr/local/go/bin
log_success "Go $go_version installed"
}
install_rust() {
log_info "Installing Rust..."
if command -v rustc &> /dev/null; then
log_warning "Rust is already installed"
return
fi
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
# Add cargo to PATH in .bashrc and .zshrc
local cargo_source='source $HOME/.cargo/env'
if ! grep -q ".cargo/env" "$HOME/.bashrc" 2>/dev/null; then
echo "$cargo_source" >> "$HOME/.bashrc"
fi
if [[ -f "$HOME/.zshrc" ]] && ! grep -q ".cargo/env" "$HOME/.zshrc"; then
echo "$cargo_source" >> "$HOME/.zshrc"
fi
log_success "Rust installed"
}
install_lua() {
log_info "Installing Lua..."
local lua_packages=(
"lua5.4"
"luajit"
"luarocks"
)
install_apt_packages "${lua_packages[@]}"
log_success "Lua installed"
}
# Install terminal emulators and tools
install_wezterm() {
log_info "Installing WezTerm..."
if command -v wezterm &> /dev/null; then
log_warning "WezTerm is already installed"
return
fi
# Add WezTerm repository
curl -fsSL https://apt.fury.io/wez/gpg.key | sudo gpg --yes --dearmor -o /usr/share/keyrings/wezterm-fury.gpg
echo 'deb [signed-by=/usr/share/keyrings/wezterm-fury.gpg] https://apt.fury.io/wez/ * *' | sudo tee /etc/apt/sources.list.d/wezterm.list
sudo apt update
install_apt_packages "wezterm"
log_success "WezTerm installed"
}
# Install additional tools (customize this section)
install_additional_tools() {
log_info "Installing additional tools..."
# Add your favorite tools here
local additional_packages=(
"fzf" # Fuzzy finder
"ripgrep" # Better grep
"fd-find" # Better find
"bat" # Better cat
"exa" # Better ls
"docker.io" # Containerization
"docker-compose" # Docker Compose
)
install_apt_packages "${additional_packages[@]}"
# Install Node.js via NodeSource
if ! command -v node &> /dev/null; then
log_info "Installing Node.js..."
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
install_apt_packages "nodejs"
fi
# Add user to docker group
if groups | grep -q docker; then
log_warning "User already in docker group"
else
sudo usermod -aG docker "$USER"
log_success "Added user to docker group (requires logout/login)"
fi
log_success "Additional tools installed"
}
# Install development editors/IDEs
install_editors() {
log_info "Installing editors and IDEs..."
# VS Code
if ! command -v code &> /dev/null; then
log_info "Installing Visual Studio Code..."
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt update
install_apt_packages "code"
fi
log_success "Editors installed"
}
# Cleanup
cleanup() {
log_info "Cleaning up..."
sudo apt autoremove -y
sudo apt autoclean
log_success "Cleanup complete"
}
# Main installation menu
main_menu() {
echo -e "${BLUE}===========================================${NC}"
echo -e "${BLUE} Ubuntu Development Setup Script${NC}"
echo -e "${BLUE}===========================================${NC}"
echo
# System update (always run)
update_system
# Basic dev tools
if prompt_yes_no "Install basic development tools?" "y"; then
install_dev_tools
fi
# Shell setup
if prompt_yes_no "Setup Zsh with Oh My Zsh?" "y"; then
setup_zsh
fi
# Programming languages
echo
log_info "Programming Languages:"
if prompt_yes_no "Install Go?" "y"; then
install_golang
fi
if prompt_yes_no "Install Rust?" "y"; then
install_rust
fi
if prompt_yes_no "Install Lua?" "y"; then
install_lua
fi
# Terminal tools
echo
log_info "Terminal Tools:"
if prompt_yes_no "Install WezTerm?" "y"; then
install_wezterm
fi
# Additional tools
if prompt_yes_no "Install additional development tools?" "y"; then
install_additional_tools
fi
# Editors
if prompt_yes_no "Install editors (VS Code)?" "y"; then
install_editors
fi
# Cleanup
cleanup
echo
log_success "Setup complete!"
echo -e "${YELLOW}Note: You may need to logout and login again for some changes to take effect.${NC}"
echo -e "${YELLOW}Run 'source ~/.bashrc' or 'source ~/.zshrc' to reload your shell configuration.${NC}"
}
# Run the script
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main_menu
fi