-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev-environment-config.sh
156 lines (120 loc) · 3.93 KB
/
dev-environment-config.sh
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
#!/bin/bash
# VM Development Environment Setup Script
# Version: 1.0.0
# Author: Yashwanth A
# Description: Automated setup for VM development environment
# Color codes for terminal output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Logging function
log() {
echo -e "${GREEN}[✓] $1${NC}"
}
# Error handling function
error() {
echo -e "${RED}[✗] ERROR: $1${NC}"
exit 1
}
# Prerequisite check function
check_prerequisites() {
echo -e "${YELLOW}Checking system prerequisites...${NC}"
# Check for required packages
REQUIRED_PACKAGES=("openssh-client" "net-tools" "curl" "wget")
for pkg in "${REQUIRED_PACKAGES[@]}"; do
if ! dpkg -s "$pkg" >/dev/null 2>&1; then
echo "Installing $pkg..."
sudo apt-get install -y "$pkg" || error "Could not install $pkg"
fi
done
log "All prerequisites are installed"
}
# SSH Configuration
configure_ssh() {
echo -e "${YELLOW}Configuring SSH...${NC}"
# Ensure SSH service is installed and running
sudo apt-get install -y openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh
# Configure SSH config for better security
sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo systemctl restart ssh
log "SSH configured successfully"
}
# Network Configuration
configure_network() {
echo -e "${YELLOW}Configuring Network...${NC}"
# Detect network interfaces
INTERFACES=$(ip -o link show | awk -F': ' '{print $2}' | grep -v "lo")
echo "Available Network Interfaces:"
echo "$INTERFACES"
read -p "Enter the interface to configure (e.g., enp0s9): " NETWORK_INTERFACE
# Configure DHCP for the specified interface
sudo dhclient -v "$NETWORK_INTERFACE" || error "Network configuration failed"
# Display network configuration
ip addr show "$NETWORK_INTERFACE"
log "Network configured for $NETWORK_INTERFACE"
}
# X11 Forwarding Setup
configure_x11_forwarding() {
echo -e "${YELLOW}Configuring X11 Forwarding...${NC}"
# Ensure X11 packages are installed
sudo apt-get install -y xauth x11-apps
# Modify SSH config for X11 Forwarding
sudo sed -i 's/#X11Forwarding no/X11Forwarding yes/' /etc/ssh/sshd_config
sudo systemctl restart ssh
# Test X11 Forwarding
xeyes &
sleep 2
killall xeyes
log "X11 Forwarding configured and tested"
}
# Firewall Configuration
configure_firewall() {
echo -e "${YELLOW}Configuring Firewall...${NC}"
# Install UFW if not present
sudo apt-get install -y ufw
# Allow SSH
sudo ufw allow ssh
sudo ufw enable
log "Firewall configured to allow SSH"
}
# Development Tools Installation
install_dev_tools() {
echo -e "${YELLOW}Installing Development Tools...${NC}"
# Core development tools
sudo apt-get update
sudo apt-get install -y \
build-essential \
git \
curl \
wget \
software-properties-common
# Optional: Install programming language runtimes
# Uncomment and modify as needed
# sudo apt-get install -y python3 python3-pip
# sudo apt-get install -y nodejs npm
log "Development tools installed"
}
# Main execution
main() {
echo -e "${YELLOW}Starting VM Development Environment Setup${NC}"
# Ensure script is run with sudo
if [[ $EUID -ne 0 ]]; then
error "This script must be run with sudo privileges"
fi
check_prerequisites
configure_ssh
configure_network
configure_x11_forwarding
configure_firewall
install_dev_tools
echo -e "${GREEN}
╔═════════════════════════════════════╗
║ Setup Complete! 🎉 ║
╚═════════════════════════════════════╝
${NC}"
}
# Execute main function
main