-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.sh
More file actions
278 lines (202 loc) · 8.61 KB
/
main.sh
File metadata and controls
278 lines (202 loc) · 8.61 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
sudo apt update -y
sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y
source /root/config.cfg
#!/bin/bash
versionWgcf="2.2.11"
downloadFilenameWgcf="wgcf_${versionWgcf}_linux_amd64"
configWgcfBinPath="/usr/local/bin"
configWgcfConfigFolderPath="${HOME}/wireguard"
configWgcfAccountFilePath="${configWgcfConfigFolderPath}/wgcf-account.toml"
configWgcfProfileFilePath="${configWgcfConfigFolderPath}/wgcf-profile.conf"
configWARPPortFilePath="${configWgcfConfigFolderPath}/warp-port"
configWireGuardConfigFileFolder="/etc/wireguard"
configWireGuardConfigFilePath="/etc/wireguard/wgcf.conf"
configWireGuardDNSBackupFilePath="/etc/resolv_warp_bak.conf"
configWarpPort="40000"
osKernelVersionFull=$(uname -r)
osKernelVersionBackup=$(uname -r | awk -F "-" '{print $1}')
osKernelVersionShort=$(uname -r | cut -d- -f1 | awk -F "." '{print $1"."$2}')
osKernelBBRStatus=""
function getGithubLatestReleaseVersion(){
# https://github.com/p4gefau1t/trojan-go/issues/63
wget --no-check-certificate -qO- https://api.github.com/repos/$1/tags | grep 'name' | cut -d\" -f4 | head -1 | cut -b 2-
}
function installSoftDownload(){
PACKAGE_LIST=( "wget" "curl" "git" "unzip" "apt-transport-https" "cpu-checker" "bc" "cron" )
# 检查所有软件包是否已安装
for package in "${PACKAGE_LIST[@]}"; do
if ! dpkg -l | grep -qw "$package"; then
# green "$package is not installed. apt-get Installing..."
apt-get install -y "$package"
fi
done
if ! dpkg -l | grep -qw curl; then
apt-get -y install wget curl git
fi
if ! dpkg -l | grep -qw ca-certificates; then
apt-get -y install ca-certificates dmidecode
update-ca-certificates
fi
}
function installWireguard(){
if [[ -f "${configWireGuardConfigFilePath}" ]]; then
exit
fi
isKernelSupportWireGuardVersion="5.6"
isKernelBuildInWireGuardModule="no"
if versionCompareWithOp "${isKernelSupportWireGuardVersion}" "${osKernelVersionShort}" ">"; then
isKernelBuildInWireGuardModule="no"
else
isKernelBuildInWireGuardModule="yes"
fi
isContinueInput=${isContinueInput:-Y}
sudo apt --fix-broken install -y
sudo apt-get update
sudo apt install -y openresolv
# sudo apt install -y resolvconf
sudo apt install -y net-tools iproute2 dnsutils
echo
if [[ ${isKernelBuildInWireGuardModule} == "yes" ]]; then
echo
sudo apt install -y wireguard-tools
else
# 安装 wireguard-dkms 后 ubuntu 20 系统 会同时安装 5.4.0-71 内核
echo
sudo apt install -y wireguard
# sudo apt install -y wireguard-tools
fi
# if [[ ! -L "/usr/local/bin/resolvconf" ]]; then
# ln -s /usr/bin/resolvectl /usr/local/bin/resolvconf
# fi
sudo systemctl enable systemd-resolved.service
sudo systemctl start systemd-resolved.service
installWGCF
}
function installWGCF(){
versionWgcf=$(getGithubLatestReleaseVersion "ViRb3/wgcf")
downloadFilenameWgcf="wgcf_${versionWgcf}_linux_amd64"
mkdir -p ${configWgcfConfigFolderPath}
mkdir -p ${configWgcfBinPath}
mkdir -p ${configWireGuardConfigFileFolder}
cd ${configWgcfConfigFolderPath}
# https://github.com/ViRb3/wgcf/releases/download/v2.2.10/wgcf_2.2.10_linux_amd64
wget -O ${configWgcfConfigFolderPath}/wgcf --no-check-certificate "https://github.com/ViRb3/wgcf/releases/download/v${versionWgcf}/${downloadFilenameWgcf}"
if [[ -f ${configWgcfConfigFolderPath}/wgcf ]]; then
echo
else
exit 255
fi
sudo chmod +x ${configWgcfConfigFolderPath}/wgcf
cp ${configWgcfConfigFolderPath}/wgcf ${configWgcfBinPath}
# ${configWgcfConfigFolderPath}/wgcf register --config "${configWgcfAccountFilePath}"
if [[ -f ${configWgcfAccountFilePath} ]]; then
echo
else
yes | ${configWgcfConfigFolderPath}/wgcf register
fi
isWARPLicenseKeyInput=$WARP_License
isWARPLicenseKeyInput=${isWARPLicenseKeyInput:-n}
if [[ ${isWARPLicenseKeyInput} == [Nn] ]]; then
echo
else
sed -i "s/license_key =.*/license_key = \"${isWARPLicenseKeyInput}\"/g" ${configWgcfAccountFilePath}
WGCF_LICENSE_KEY="${isWARPLicenseKeyInput}" wgcf update
fi
if [[ -f ${configWgcfProfileFilePath} ]]; then
echo
else
yes | ${configWgcfConfigFolderPath}/wgcf generate
fi
cp ${configWgcfProfileFilePath} ${configWireGuardConfigFilePath}
enableWireguardIPV6OrIPV4
sudo wg-quick up wgcf
echo "curl -6 ip.p3terx.com"
curl -6 ip.p3terx.com
isWireguardIpv6Working=$(curl -6 ip.p3terx.com | grep CLOUDFLARENET )
sudo wg-quick down wgcf
echo
sudo systemctl daemon-reload
# 设置开机启动
sudo systemctl enable wg-quick@wgcf
# 启用守护进程
sudo systemctl start wg-quick@wgcf
# (crontab -l ; echo "12 6 * * 1 systemctl restart wg-quick@wgcf ") | sort - | uniq - | crontab -
checkWireguardBootStatus
}
function enableWireguardIPV6OrIPV4(){
# https://p3terx.com/archives/use-cloudflare-warp-to-add-extra-ipv4-or-ipv6-network-support-to-vps-servers-for-free.html
sudo systemctl stop wg-quick@wgcf
cp /etc/resolv.conf ${configWireGuardDNSBackupFilePath}
sed -i '/nameserver 2a00\:1098\:2b\:\:1/d' /etc/resolv.conf
sed -i '/nameserver 8\.8/d' /etc/resolv.conf
sed -i '/nameserver 9\.9/d' /etc/resolv.conf
sed -i '/nameserver 1\.1\.1\.1/d' /etc/resolv.conf
isAddNetworkIPv6Input=${isAddNetworkIPv6Input:-1}
if [[ ${isAddNetworkIPv6Input} == [2] ]]; then
# 为 IPv6 Only 服务器添加 IPv4 网络支持
sed -i 's/^AllowedIPs = \:\:\/0/# AllowedIPs = \:\:\/0/g' ${configWireGuardConfigFilePath}
sed -i 's/# AllowedIPs = 0\.0\.0\.0/AllowedIPs = 0\.0\.0\.0/g' ${configWireGuardConfigFilePath}
sed -i 's/engage\.cloudflareclient\.com/\[2606\:4700\:d0\:\:a29f\:c001\]/g' ${configWireGuardConfigFilePath}
sed -i 's/162\.159\.192\.1/\[2606\:4700\:d0\:\:a29f\:c001\]/g' ${configWireGuardConfigFilePath}
sed -i 's/^DNS = 1\.1\.1\.1/DNS = 2620:fe\:\:10,2001\:4860\:4860\:\:8888,2606\:4700\:4700\:\:1111/g' ${configWireGuardConfigFilePath}
sed -i 's/^DNS = 8\.8\.8\.8,8\.8\.4\.4,1\.1\.1\.1,9\.9\.9\.10/DNS = 2620:fe\:\:10,2001\:4860\:4860\:\:8888,2606\:4700\:4700\:\:1111/g' ${configWireGuardConfigFilePath}
echo "nameserver 2a00:1098:2b::1" >> /etc/resolv.conf
else
# 为 IPv4 Only 服务器添加 IPv6 网络支持
sed -i 's/^AllowedIPs = 0\.0\.0\.0/# AllowedIPs = 0\.0\.0\.0/g' ${configWireGuardConfigFilePath}
sed -i 's/# AllowedIPs = \:\:\/0/AllowedIPs = \:\:\/0/g' ${configWireGuardConfigFilePath}
sed -i 's/engage\.cloudflareclient\.com/162\.159\.192\.1/g' ${configWireGuardConfigFilePath}
sed -i 's/\[2606\:4700\:d0\:\:a29f\:c001\]/162\.159\.192\.1/g' ${configWireGuardConfigFilePath}
sed -i 's/^DNS = 1\.1\.1\.1/DNS = 8\.8\.8\.8,8\.8\.4\.4,1\.1\.1\.1,9\.9\.9\.10/g' ${configWireGuardConfigFilePath}
sed -i 's/^DNS = 2620:fe\:\:10,2001\:4860\:4860\:\:8888,2606\:4700\:4700\:\:1111/DNS = 8\.8\.8\.8,1\.1\.1\.1,9\.9\.9\.10/g' ${configWireGuardConfigFilePath}
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
echo "nameserver 1.1.1.1" >> /etc/resolv.conf
#echo "nameserver 9.9.9.9" >> /etc/resolv.conf
echo "nameserver 9.9.9.10" >> /etc/resolv.conf
fi
# -n 不为空
if [[ -n $1 ]]; then
sudo systemctl start wg-quick@wgcf
else
preferIPV4
fi
}
function preferIPV4(){
if [[ -f "/etc/gai.conf" ]]; then
sed -i '/^precedence \:\:ffff\:0\:0/d' /etc/gai.conf
sed -i '/^label 2002\:\:\/16/d' /etc/gai.conf
fi
# 设置 IPv4 优先
echo "precedence ::ffff:0:0/96 100" >> /etc/gai.conf
curl ip.p3terx.com
}
function checkWireguardBootStatus(){
echo
isWireguardBootSuccess=$(systemctl status wg-quick@wgcf | grep -E "Active: active")
if [[ -z "${isWireguardBootSuccess}" ]]; then
echo
else
echo "wgcf trace"
wgcf trace
fi
}
if [ "$WARP_IPv6" == "yes" ]; then
installSoftDownload
installWireguard
else
echo "skipping WARP installation"
fi
# Path to the script you want to run after reboot
SCRIPT_PATH="/root/after_reboot.sh"
sudo wget https://raw.githubusercontent.com/xmohammad1/steupnode/main/after_reboot.sh -O "$SCRIPT_PATH"
# Ensure the script is executable
sudo chmod +x "$SCRIPT_PATH"
# Define the cron job
CRON_JOB="@reboot tmux new-session -d -s update-session 'bash /root/after_reboot.sh'"
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
echo "Cron job added: $CRON_JOB"
echo "Waiting 15 Sec before reboot"
sleep 15
# Reboot the system
sudo reboot