-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomated-setup.sh
More file actions
224 lines (176 loc) · 5.64 KB
/
Copy pathautomated-setup.sh
File metadata and controls
224 lines (176 loc) · 5.64 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
#!/bin/bash
# Ubuntu-WSL2-DevOps-Setup Automated Installer
# This script automates the setup process
set -e # Exit on 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
# Functions
print_header() {
echo -e "\n${BLUE}=== $1 ===${NC}\n"
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
# Start
clear
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════╗"
echo "║ Ubuntu-WSL2-DevOps-Setup Automated Install ║"
echo "║ Setting up your environment ║"
echo "╚═══════════════════════════════════════════════╝"
echo -e "${NC}"
# Check if running in WSL2
print_header "Checking System Requirements"
if ! grep -qi microsoft /proc/version; then
print_error "Not running in WSL2 Ubuntu"
print_warning "This script is designed for WSL2 Ubuntu 24.04.3 LTS"
exit 1
fi
print_success "WSL2 Ubuntu environment detected"
# Check if running as user (not root)
if [ "$EUID" -eq 0 ]; then
print_error "Don't run this script as root. Run as regular user."
exit 1
fi
print_success "Running as user: $(whoami)"
# Update system
print_header "Updating System Packages"
sudo apt update
sudo apt upgrade -y -qq
print_success "System packages updated"
# Install essential tools
print_header "Installing Essential Tools"
ESSENTIAL_PACKAGES=(
"build-essential"
"curl"
"wget"
"git"
"nano"
"vim"
"htop"
"net-tools"
"openssh-client"
"ca-certificates"
)
for package in "${ESSENTIAL_PACKAGES[@]}"; do
if dpkg -l | grep -q "^ii $package"; then
print_success "$package already installed"
else
print_warning "Installing $package..."
sudo apt install -y -qq "$package"
print_success "$package installed"
fi
done
# Create development directories
print_header "Creating Development Directories"
mkdir -p ~/projects/{devops,docker,kubernetes}
mkdir -p ~/backups
print_success "Development directories created:"
print_success " ~/projects/devops"
print_success " ~/projects/docker"
print_success " ~/projects/kubernetes"
print_success " ~/backups"
# Configure Git (prompt for input)
print_header "Configuring Git"
read -p "Enter your name (for Git config): " git_name
read -p "Enter your email (for Git config): " git_email
git config --global user.name "$git_name"
git config --global user.email "$git_email"
git config --global core.editor "nano"
git config --global init.defaultBranch "main"
print_success "Git configured:"
git config --list | grep user
git config --list | grep core.editor
# Backup existing bashrc
print_header "Backing Up Configuration Files"
if [ -f ~/.bashrc ]; then
cp ~/.bashrc ~/backups/bashrc.backup.$(date +%Y%m%d-%H%M%S)
print_success "Existing .bashrc backed up"
fi
if [ -f ~/.gitconfig ]; then
cp ~/.gitconfig ~/backups/gitconfig.backup.$(date +%Y%m%d-%H%M%S)
print_success "Existing .gitconfig backed up"
fi
# Add DevOps aliases to bashrc
print_header "Adding Custom Aliases"
cat >> ~/.bashrc << 'EOF'
# ============================================
# Custom DevOps Aliases
# ============================================
alias d='docker'
alias dc='docker-compose'
alias k='kubectl'
alias gs='git status'
alias ga='git add'
alias gc='git commit -m'
alias gp='git push'
alias gl='git log --oneline -10'
alias gd='git diff'
alias gb='git branch'
# Directory navigation
alias cddev='cd ~/projects/devops'
alias cddk='cd ~/projects/docker'
alias cdk8s='cd ~/projects/kubernetes'
alias cdproj='cd ~/projects'
# System utilities
alias ll='ls -lah'
alias la='ls -A'
alias cls='clear'
alias apt-update='sudo apt update && sudo apt upgrade -y'
# Docker utilities
alias docker-clean='docker container prune -f && docker image prune -f'
alias docker-logs='docker logs -f'
alias docker-ps='docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"'
# ============================================
# DevOps Environment Variables
# ============================================
export DOCKER_BUILDKIT=1
export PYTHONUNBUFFERED=1
export PIP_NO_CACHE_DIR=1
# ============================================
# END Custom Configuration
# ============================================
EOF
print_success "Custom aliases added to ~/.bashrc"
# Reload bashrc
source ~/.bashrc
print_success ".bashrc reloaded"
# Verify key tools
print_header "Verifying Installation"
echo "Docker version:"
docker --version
echo -e "\nGit version:"
git --version
echo -e "\nPython version:"
python3 --version
echo -e "\nTotal packages installed:"
apt list --installed 2>/dev/null | wc -l
# Summary
print_header "Installation Complete!"
echo -e "${GREEN}✓ System updated"
echo "✓ Essential tools installed"
echo "✓ Development directories created"
echo "✓ Git configured"
echo "✓ Custom aliases added"
echo "✓ DevOps environment ready${NC}"
echo -e "\n${BLUE}Next Steps:${NC}"
echo "1. Run 'source ~/.bashrc' to load aliases (or open new terminal)"
echo "2. Verify setup: bash scripts/verify-setup.sh"
echo "3. Read: docs/02-INSTALLATION-GUIDE.md"
echo "4. Start learning: docs/08-NEXT-STEPS.md"
echo -e "\n${YELLOW}Helpful commands:${NC}"
echo " cd ~/projects - Go to projects directory"
echo " docker ps - List running containers"
echo " git status - Check git status"
echo " python3 -m venv env - Create virtual environment"
echo -e "\n${GREEN}Happy DevOps Learning! 🚀${NC}\n"