-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscript.sh
129 lines (123 loc) · 4.33 KB
/
script.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
#!/bin/bash
echo -e "\033[1;33m=========================================="
echo -e "Created by Parsa in OPIran club https://t.me/OPIranClub"
echo -e "Love Iran :)"
echo -e "==========================================\033[0m"
read -p "Are you running this script on the IRAN server or the FOREIGN server? (IRAN/FOREIGN): " server_location_en
echo -e "\033[1;33mUpdating and installing required packages...\033[0m"
sudo apt update
sudo apt-get install iproute2 -y
sudo apt install nano -y
sudo apt install netplan.io -y
function ask_yes_no() {
local prompt=$1
local answer=""
while true; do
read -p "$prompt (yes/no): " answer
if [[ "$answer" == "yes" || "$answer" == "no" ]]; then
echo "$answer"
break
else
echo -e "\033[1;31mOnly yes or no allowed.\033[0m"
fi
done
}
if [[ "$server_location_en" == "IRAN" || "$server_location_en" == "iran" ]]; then
read -p "Please enter the IPv4 address of the IRAN server: " iran_ip
read -p "Please enter the MTU (press Enter for default 1420): " mtu
mtu=${mtu:-1420}
read -p "How many FOREIGN servers do you have? " n_server
declare -a foreign_ips
for (( i=1; i<=$n_server; i++ )); do
read -p "Enter IPv4 of FOREIGN server #$i: " temp_ip
foreign_ips[i]=$temp_ip
done
for (( i=1; i<=$n_server; i++ )); do
if (( i % 2 == 1 )); then
y=$i
else
y=$((i+1))
fi
netplan_file="/etc/netplan/pdtun${i}.yaml"
tunnel_name="tunel0$y"
sudo bash -c "cat > $netplan_file <<EOF
network:
version: 2
tunnels:
$tunnel_name:
mode: sit
local: $iran_ip
remote: ${foreign_ips[i]}
addresses:
- 2619:db8:85a3:1b2e::$((2*i))/64
mtu: $mtu
routes:
- to: 2619:db8:85a3:1b2e::$y/128
scope: link
EOF"
sudo netplan apply
sudo systemctl unmask systemd-networkd.service
sudo systemctl start systemd-networkd
sudo netplan apply
network_file="/etc/systemd/network/tun${i}.network"
sudo bash -c "cat > $network_file <<EOF
[Network]
Address=2619:db8:85a3:1b2e::$((2*i))/64
Gateway=2619:db8:85a3:1b2e::$((2*i - 1))
EOF"
echo -e "\033[1;37mThis is your Private-IPv6 for IRAN server #$i: 2619:db8:85a3:1b2e::$((2*i))\033[0m"
done
sudo systemctl restart systemd-networkd
reboot_choice=$(ask_yes_no "Operation completed successfully. Please reboot the system")
if [ "$reboot_choice" == "yes" ]; then
echo -e "\033[1;33mRebooting the system...\033[0m"
sudo reboot
else
echo -e "\033[1;33mOperation completed successfully. Reboot required.\033[0m"
fi
else
read -p "Please enter the IPv4 address of the FOREIGN server: " foreign_ip
read -p "Please enter the IPv4 address of the IRAN server: " iran_ip
read -p "Please enter the MTU (press Enter for default 1420): " mtu
mtu=${mtu:-1420}
read -p "Which number is this FOREIGN server? (If you have multiple foreign servers, type which one this is. If only one, type 1): " server_number
if (( server_number % 2 == 0 )); then
this_server=$((server_number + 1))
else
this_server=$server_number
fi
sudo bash -c "cat > /etc/netplan/pdtun.yaml <<EOF
network:
version: 2
tunnels:
tunel01:
mode: sit
local: $foreign_ip
remote: $iran_ip
addresses:
- 2619:db8:85a3:1b2e::$this_server/64
mtu: $mtu
routes:
- to: 2619:db8:85a3:1b2e::$this_server/128
scope: link
EOF"
sudo netplan apply
sudo systemctl unmask systemd-networkd.service
sudo systemctl start systemd-networkd
sudo netplan apply
gateway_for_foreign=$((this_server + 1))
sudo bash -c "cat > /etc/systemd/network/tun0.network <<EOF
[Network]
Address=2619:db8:85a3:1b2e::$this_server/64
Gateway=2619:db8:85a3:1b2e::$gateway_for_foreign
EOF"
echo -e "\033[1;37mThis is your Private-IPv6 for your FOREIGN server: 2619:db8:85a3:1b2e::$this_server\033[0m"
sudo systemctl restart systemd-networkd
reboot_choice=$(ask_yes_no "Operation completed successfully. Please reboot the system")
if [ "$reboot_choice" == "yes" ]; then
echo -e "\033[1;33mRebooting the system...\033[0m"
sudo reboot
else
echo -e "\033[1;33mOperation completed successfully. Reboot required.\033[0m"
fi
fi