-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathwireguard.sh
182 lines (160 loc) · 7.69 KB
/
wireguard.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
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
#####################################################
# Created by cryptopool.builders for crypto use...
#####################################################
source $STORAGE_ROOT/yiimp/.wireguard.conf
source /etc/multipool.conf
sudo add-apt-repository ppa:wireguard/wireguard -y
sudo apt-get update -y
sudo apt-get install wireguard-dkms wireguard-tools -y
(umask 077 && printf "[Interface]\nPrivateKey = " | sudo tee /etc/wireguard/wg0.conf > /dev/null)
wg genkey | sudo tee -a /etc/wireguard/wg0.conf | wg pubkey | sudo tee /etc/wireguard/publickey
if [[ ("$server_type" == "db") ]]; then
echo "ListenPort = 6121" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "SaveConfig = true" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "Address = ${DBInternalIP}/24" | hide_output sudo tee -a /etc/wireguard/wg0.conf
cd $HOME
sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0
sudo ufw allow 6121
clear
dbpublic=${PUBLIC_IP}
mypublic="$(sudo cat /etc/wireguard/publickey)"
echo 'Public Ip: '"${dbpublic}"'
Public Key: '"${mypublic}"'
wireguard='true'
' | sudo -E tee $STORAGE_ROOT/yiimp/.wireguard_public.conf >/dev/null 2>&1;
echo Please begin the Wireguard installation on your other servers...
echo
echo The public IP of this box is, $dbpublic
echo
echo The Public key of this box is, $mypublic
echo
elif [[ ("$server_type" == "dbshared") ]]; then
echo "ListenPort = 6121" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "SaveConfig = true" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "Address = ${DBInternalIP}/24" | hide_output sudo tee -a /etc/wireguard/wg0.conf
cd $HOME
sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0
sudo ufw allow 6121
clear
dbpublic=${PUBLIC_IP}
mypublic="$(sudo cat /etc/wireguard/publickey)"
echo 'Public Ip: '"${dbpublic}"'
Public Key: '"${mypublic}"'
wireguard='true'
' | sudo -E tee $STORAGE_ROOT/yiimp/.wireguard_public.conf >/dev/null 2>&1;
echo Please begin the Wireguard installation on your other servers...
echo
echo The public IP of this box is, $dbpublic
echo
echo The Public key of this box is, $mypublic
echo
elif [[ ("$server_type" == "web") ]]; then
echo "ListenPort = 6121" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "SaveConfig = true" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "Address = ${WebInternalIP}/32" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "[Peer]" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "PublicKey = ${DBPublicKey}" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "AllowedIPs = ${DBInternalIP}/24" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "Endpoint = ${DBServerIP}:6121" | hide_output sudo tee -a /etc/wireguard/wg0.conf
cd $HOME
hide_output sudo systemctl start wg-quick@wg0
hide_output sudo systemctl enable wg-quick@wg0
sudo ufw allow 6121
clear
mypublic="$(sudo cat /etc/wireguard/publickey)"
webinternal=${WebInternalIP}
webpublic=${PUBLIC_IP}
clear
echo 'sudo wg set wg0 peer '"${mypublic}"' endpoint '"${webpublic}"':6121 allowed-ips '"${webinternal}"'/32
' | sudo -E tee $STORAGE_ROOT/yiimp/.wireguard_command.conf >/dev/null 2>&1;
echo 'wireguard=true
' | sudo -E tee $STORAGE_ROOT/yiimp/.wireguard_public.conf >/dev/null 2>&1;
echo "Copy this command and run it on the DB Server, Stratum Server, and Daemon Server"
echo
echo "sudo wg set wg0 peer ${mypublic} endpoint ${webpublic}:6121 allowed-ips ${webinternal}/32"
echo
echo
elif [[ ("$server_type" == "stratum") ]]; then
echo "ListenPort = 6121" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "SaveConfig = true" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "Address = ${StratumInternalIP}/32" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "[Peer]" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "PublicKey = ${DBPublicKey}" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "AllowedIPs = ${DBInternalIP}/24" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "Endpoint = ${DBServerIP}:6121" | hide_output sudo tee -a /etc/wireguard/wg0.conf
cd $HOME
sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0
sudo ufw allow 6121
clear
mypublic="$(sudo cat /etc/wireguard/publickey)"
stratinternal=${StratumInternalIP}
stratpublic=${PUBLIC_IP}
clear
echo 'sudo wg set wg0 peer '"${mypublic}"' endpoint '"${stratpublic}"':6121 allowed-ips '"${stratinternal}"'/32
' | sudo -E tee $STORAGE_ROOT/yiimp/.wireguard_command.conf >/dev/null 2>&1;
echo 'wireguard=true
' | sudo -E tee $STORAGE_ROOT/yiimp/.wireguard_public.conf >/dev/null 2>&1;
echo "Copy this command and run it on the DB Server, Web Server, and Daemon Server"
echo
echo "sudo wg set wg0 peer ${mypublic} endpoint ${stratpublic}:6121 allowed-ips ${stratinternal}/32"
echo
echo
elif [[ ("$server_type" == "additional") ]]; then
echo "ListenPort = 6121" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "SaveConfig = true" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "Address = ${AdditionalInternalIP}/32" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "[Peer]" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "PublicKey = ${DBPublicKey}" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "AllowedIPs = ${DBInternalIP}/24" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "Endpoint = ${DBServerIP}:6121" | hide_output sudo tee -a /etc/wireguard/wg0.conf
cd $HOME
sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0
sudo ufw allow 6121
clear
mypublic="$(sudo cat /etc/wireguard/publickey)"
additionalinternal=${AdditionalInternalIP}
additionalpublic=${PUBLIC_IP}
clear
echo 'sudo wg set wg0 peer '"${mypublic}"' endpoint '"${additionalpublic}"':6121 allowed-ips '"${additionalinternal}"'/32
' | sudo -E tee $STORAGE_ROOT/yiimp/.wireguard_command.conf >/dev/null 2>&1;
echo 'wireguard=true
' | sudo -E tee $STORAGE_ROOT/yiimp/.wireguard_public.conf >/dev/null 2>&1;
echo "Copy this command and run it on the DB Server, Web Server, and Daemon Server, any other additional servers"
echo
echo "sudo wg set wg0 peer ${mypublic} endpoint ${additionalpublic}:6121 allowed-ips ${additionalinternal}/32"
echo
echo
elif [[ ("$server_type" == "daemon") ]]; then
echo "ListenPort = 6121" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "SaveConfig = true" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "Address = ${DaemonInternalIP}/32" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "[Peer]" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "PublicKey = ${DBPublicKey}" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "AllowedIPs = ${DBInternalIP}/24" | hide_output sudo tee -a /etc/wireguard/wg0.conf
echo "Endpoint = ${DBServerIP}:6121" | hide_output sudo tee -a /etc/wireguard/wg0.conf
cd $HOME
sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0
sudo ufw allow 6121
clear
mypublic="$(sudo cat /etc/wireguard/publickey)"
daemoninternal=${DaemonInternalIP}
daemonpublic=${PUBLIC_IP}
clear
echo 'sudo wg set wg0 peer '"${mypublic}"' endpoint '"${daemonpublic}"':6121 allowed-ips '"${daemoninternal}"'/32
' | sudo -E tee $STORAGE_ROOT/yiimp/.wireguard_command.conf >/dev/null 2>&1;
echo 'wireguard=true
' | sudo -E tee $STORAGE_ROOT/yiimp/.wireguard_public.conf >/dev/null 2>&1;
echo "Copy this command and run it on the DB Server, Web Server, and Stratum Server"
echo
echo "sudo wg set wg0 peer ${mypublic} endpoint ${daemonpublic}:6121 allowed-ips ${daemoninternal}/32"
echo
echo
fi
echo
echo "After installing Wireguard on all of your servers run, multipool from the DB server only!!"
exit 0