-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDocker-DNS-Config.sh
87 lines (73 loc) · 2.63 KB
/
Docker-DNS-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
#!/bin/bash
# Check if the script is run as root or with sudo
if [ "$EUID" -ne 0 ]; then
echo "This script must be run as root or with sudo."
exit 1
fi
# Function to validate an IP address
validate_ip() {
local ip="$1"
if [[ ! "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid IP address format: $ip"
exit 1
fi
}
# Function to install Docker and Docker Compose
install_docker() {
echo "Installing Docker and Docker Compose..."
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
rm get-docker.sh
# Install Docker Compose
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
echo "Docker and Docker Compose installed successfully!"
}
# Custom message by Dry-Stan Nex
custom_message() {
echo "-------------------------------------------------------------"
echo "This script is powered by Dry-Stan Nex, your script assistant!"
echo "Enjoy using this script to configure your VPS and Docker."
echo "-------------------------------------------------------------"
}
# Prompt the user to choose an option
echo "Select an option:"
echo "1. Use default DNS servers (shecan)"
echo "2. Enter custom DNS servers"
echo "3. Enable default settings and install Docker"
read -p "Enter your choice (1/2/3): " choice
# Default DNS servers (shecan)
default_dns1="185.51.200.2"
default_dns2="178.22.122.100"
# Function to change DNS servers
change_dns() {
echo "Changing DNS servers..."
sed -i '/^DNS=/d' /etc/systemd/resolved.conf
sed -i '/^FallbackDNS=/d' /etc/systemd/resolved.conf
bash -c "echo 'DNS=$1' >> /etc/systemd/resolved.conf"
bash -c "echo 'FallbackDNS=$2' >> /etc/systemd/resolved.conf"
systemctl restart systemd-resolved
echo "DNS servers updated successfully!"
}
if [ "$choice" == "1" ]; then
# Use default DNS servers (shecan)
change_dns "$default_dns1" "$default_dns2"
custom_message
elif [ "$choice" == "2" ]; then
# Prompt the user to enter custom DNS servers
read -p "Enter the first DNS server IP: " custom_dns1
read -p "Enter the second DNS server IP: " custom_dns2
# Validate custom DNS server IP addresses
validate_ip "$custom_dns1"
validate_ip "$custom_dns2"
change_dns "$custom_dns1" "$custom_dns2"
custom_message
elif [ "$choice" == "3" ]; then
# Enable default settings and install Docker
change_dns "$default_dns1" "$default_dns2"
install_docker
custom_message
else
echo "Invalid choice. Please select 1, 2, or 3."
fi