Selaa lähdekoodia

Update wg5clients.sh

蘭雅sRGB 6 vuotta sitten
vanhempi
sitoutus
1b6c3752a9
1 muutettua tiedostoa jossa 46 lisäystä ja 21 poistoa
  1. 46 21
      Wireguard/wg5clients.sh

+ 46 - 21
Wireguard/wg5clients.sh

@@ -4,12 +4,43 @@
 #    本脚本(WireGuard 多用户配置)一键安装短网址
 #    wget -qO- https://git.io/fpnQt | bash
 
-#    本脚本适合已经安装 WireGuard VPN 的vps
-#    如果你的vps没有安装 WireGuard ,可以用下行命令先安装
+#############################################################
+help_info()
+{
+cat  <<EOF
+
+# 一键安装wireguard 脚本 Debian 9 (源:逗比网安装笔记)
+wget -qO- git.io/fptwc | bash
+
+# 一键安装wireguard 脚本 Ubuntu   (源:逗比网安装笔记)
+wget -qO- git.io/fpcnL | bash
+
+# CentOS7一键脚本安装WireGuard   (https://atrandys.com/2018/886.html)
+yum install -y wget && \
+wget https://raw.githubusercontent.com/atrandys/wireguard/master/wireguard_install.sh \
+&& chmod +x wireguard_install.sh && ./wireguard_install.sh
+
+EOF
+}
+#############################################################
+
+#定义文字颜色
+Green="\033[32m"  && Red="\033[31m" && GreenBG="\033[42;37m" && RedBG="\033[41;37m" && Font="\033[0m"
+
+#定义提示信息
+Info="${Green}[信息]${Font}"  &&  OK="${Green}[OK]${Font}"  &&  Error="${Red}[错误]${Font}"
 
-#    一键安装wireguard 脚本 debian 9
-#    wget -qO- git.io/fptwc | bash
+# 检查是否安装 WireGuard
+if [ ! -f '/usr/bin/wg' ]; then
+    clear
+    echo -e "${RedBG}   一键安装 WireGuard 脚本 For Debian_9 Ubuntu Centos_7   ${Font}"
+    echo -e "${GreenBG}     开源项目:https://github.com/hongwenjun/vps_setup    ${Font}"
+    help_info
+    echo -e "${RedBG}   检测到你的vps没有正确选择脚本,请使用对应系统的脚本安装   ${Font}"
+    exit 1
+fi
 #############################################################
+
 # 定义修改端口号,适合已经安装WireGuard而不想改端口
 
 #生成随机端口
@@ -17,7 +48,7 @@ rand(){
     min=$1
     max=$(($2-$min+1))
     num=$(cat /dev/urandom | head -n 10 | cksum | awk -F ' ' '{print $1}')
-    echo $(($num%$max+$min))  
+    echo $(($num%$max+$min))
 }
 
 port=$(rand 1000 60000)
@@ -25,11 +56,11 @@ port=$(rand 1000 60000)
 mtu=1420
 host=$(hostname -s)
 
-ip_list=(2 8 18 88 188 118 158 198 168 186)
+ip_list=(2 5 8 18 88 188 118 158 198 168 186 )
 
 # 获得服务器ip,自动获取
 if [ ! -f '/usr/bin/curl' ]; then
-    apt update && apt install -y curl 
+    apt update && apt install -y curl
 fi
 serverip=$(curl -4 icanhazip.com)
 
@@ -40,6 +71,7 @@ fi
 
 # 安装 bash wgmtu 脚本用来设置服务器
 wget -O ~/wgmtu  https://raw.githubusercontent.com/hongwenjun/vps_setup/master/Wireguard/wgmtu.sh
+
 #############################################################
 
 # 转到wg配置文件目录
@@ -53,7 +85,7 @@ wg genkey | tee cprivatekey | wg pubkey > cpublickey
 cat <<EOF >wg0.conf
 [Interface]
 PrivateKey = $(cat sprivatekey)
-Address = 10.0.0.1/24 
+Address = 10.0.0.1/24
 PostUp   = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
 PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
 ListenPort = $port
@@ -84,12 +116,12 @@ PersistentKeepalive = 25
 
 EOF
 
-# 添加 1-9 多用户配置子程序
-for i in {1..9}
+# 添加 2-9 号多用户配置
+for i in {2..9}
 do
     ip=10.0.0.${ip_list[$i]}
     wg genkey | tee cprivatekey | wg pubkey > cpublickey
-    
+
     cat <<EOF >>wg0.conf
 [Peer]
 PublicKey = $(cat cpublickey)
@@ -124,12 +156,6 @@ wg-quick down wg0
 wg-quick up wg0
 wg
 
-#定义文字颜色
-Green="\033[32m"  && Red="\033[31m" && GreenBG="\033[42;37m" && RedBG="\033[41;37m" && Font="\033[0m"
-
-#定义提示信息
-Info="${Green}[信息]${Font}"  &&  OK="${Green}[OK]${Font}"  &&  Error="${Red}[错误]${Font}"
-
 conf_url=http://${serverip}:8000
 
 cat  <<EOF > ~/wg5
@@ -142,17 +168,16 @@ host=$(hostname -s)
 
 cd  /etc/wireguard/
 tar cvf  wg5clients.tar  client*  wg*
-cat /etc/wireguard/wg_${host}_1.conf | qrencode -o - -t UTF8
-echo "# 手机扫描二维码2号配置,PC使用配置复制下面文本"
+cat /etc/wireguard/wg_${host}_2.conf | qrencode -o - -t UTF8
+echo -e  "${GreenBG}#   手机扫描二维码2号配置,Windows 用配置请复制合适文本 ${Font}"
 
 cat /etc/wireguard/client.conf       && next
-cat /etc/wireguard/wg_${host}_1.conf   && next
 cat /etc/wireguard/wg_${host}_2.conf   && next
 cat /etc/wireguard/wg_${host}_3.conf   && next
 cat /etc/wireguard/wg_${host}_4.conf   && next
 
 echo -e "${RedBG}   一键安装 WireGuard 脚本 For Debian_9 Ubuntu Centos_7   ${Font}"
-echo -e "${GreenBG}    开源项目:https://github.com/hongwenjun/vps_setup    ${Font}"
+echo -e "${GreenBG}     开源项目:https://github.com/hongwenjun/vps_setup    ${Font}"
 echo
 echo -e "# ${Info} 使用${GreenBG} bash wg5 ${Font} 命令,可以临时网页下载配置和二维码"
 echo -e "# ${Info} 使用${GreenBG} bash wgmtu ${Font} 命令,重置客户端数量,设置服务器端MTU数值或服务端口号 "