-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrun.sh
executable file
·86 lines (71 loc) · 2.4 KB
/
run.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
#!/bin/bash
# 获取当前系统内核版本
kernel_version=$(uname -r)
# WireGuard 要求的最低内核版本
required_version="5.6"
# 比较内核版本,如果符合要求则打印绿色提示,否则打印红色提示
if [[ "$(printf '%s\n' "$kernel_version" "$required_version" | sort -V | head -n1)" == "$required_version" ]]; then
echo -e "\e[32m当前系统内核版本 ($kernel_version) 符合要求。\e[0m"
else
echo -e "\e[31m当前系统内核版本 ($kernel_version) 不符合要求,请升级至 $required_version 或更高版本。\e[0m"
exit 1
fi
read -p "是否自动获取公网IP地址?(y/n)" use_auto_ip
if [[ "$use_auto_ip" =~ ^[Yy]$ ]]; then
ipv4=$(curl -s https://ipv4.icanhazip.com/)
echo "获取到的IPv4地址为: $ipv4"
read -p "是否使用上面获取到的IP地址?(y/n)" use_auto_ip_result
if [[ "$use_auto_ip_result" =~ ^[Nn]$ ]]; then
read -p "请输入IPv4地址或者域名: " ipv4
fi
else
read -p "请输入IPv4地址或者域名: " ipv4
fi
read -p "请输入管理后台密码:" PASSWORD
if [ -z "$PASSWORD" ]; then
echo "密码为空,退出"
exit 1
fi
read -p "请输入管理后台访问端口:" TCP_PORT
if [ -z "$TCP_PORT" ]; then
echo "管理后台访问为空,退出"
exit 1
fi
echo "--------------------"
echo "ipv4或者域名:$ipv4"
echo "web登录的密码:$PASSWORD"
echo "管理后台访问端口:$TCP_PORT"
echo "--------------------"
echo "Do you want to continue? (y/n)"
read answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
echo "Continuing..."
else
echo "Exiting..."
exit 0
fi
docker run -d \
--name=wg-easy \
-e WG_HOST=$ipv4 \
-e PASSWORD=$PASSWORD \
-e WG_DEFAULT_ADDRESS=10.0.8.x \
-e WG_DEFAULT_DNS=223.5.5.5,223.6.6.6 \
-e WG_ALLOWED_IPS=10.0.8.0/24 \
-e WG_PERSISTENT_KEEPALIVE=25 -v $(pwd)/data/etc/wireguard:/etc/wireguard \
-e WG_PORT=$TCP_PORT\
-p $TCP_PORT:51820/udp \
-p $TCP_PORT:51821/tcp \
--cap-add=NET_ADMIN \
--cap-add=SYS_MODULE \
--sysctl="net.ipv4.conf.all.src_valid_mark=1" \
--sysctl="net.ipv4.ip_forward=1" \
--restart unless-stopped \
weejewel/wg-easy
if [ $? -ne 0 ]; then
echo "failed to start"
exit 1
fi
echo "--------------------"
echo "请在防火墙中打开$TCP_PORT端口, 需要放开udp和tcp两个协议"
echo "your admin url:http://$ipv4:$TCP_PORT"
echo "enjoy~"