#!/bin/bash
# WireGuard Shadowsocks V2Ray 服务端三合一脚本  短网址 https://git.io/vps.sh

# Usage:  bash <(curl -L -s https://git.io/vps.sh)

# 默认安装三合一  Usage:  wget -qO- git.io/vps.sh | bash
default_install(){

    # 一键安装wireguard 脚本
    wget -qO- git.io/fptwc | bash

    # V2Ray官方一键脚本
    bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)

    # 一键安装shadowsocks-libev脚本
    wget -qO- git.io/fhExJ | bash

    # 安装 WireGuard+Speeder+Udp2Raw 和 SS+Kcp+Udp2RAW 配置
    bash wgmtu setup
}

display_conf(){
    echo
    echo
    echo_SkyBlue "# ======================================="
    echo_GreenBG "# V2ray 服务端配置 /etc/v2ray/config.json"
    cat /etc/v2ray/config.json
    echo
    echo_SkyBlue "# WG+Speed+Udp2Raw 和 SS+Kcp+Udp2RAW 配置 /etc/rc.local"
    cat vps_setup.log
    echo_GreenBG "# WireGuard 客户端配置 /etc/wireguard/client.conf"
    cat /etc/wireguard/client.conf
}

base_tools(){
    # 简化判断系统 debian/centos 族群
    if [ -e '/etc/redhat-release' ]; then
        yum update -y && yum install -y  wget curl vim ca-certificates
    else
        apt update && apt install -y  wget curl vim  ca-certificates
    fi
}

wget_curl(){
    if [[ ! -e /usr/bin/wget ]]; then
        base_tools
    fi
    if [[ ! -e /usr/bin/curl ]]; then
        base_tools
    fi
}

vps_remove(){
    bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --remove
    bash wgmtu remove
    cd /root && rm -f v2ray_ss.log vps_setup.log wg5 wgmtu /var/ip_addr /etc/v2ray/config.json \
        base64_shadowsocks.conf base64_v2ray_vmess.json
}

# 设置菜单
start_menu(){
    clear
    echo_GreenBG ">  开源项目:  https://github.com/hongwenjun/vps_setup  "
    echo_SkyBlue ">  1. 默认安装 WireGuard Shadowsocks V2Ray 服务端三合一"
    echo_SkyBlue ">  2. 选择安装 WireGuard 多用户服务端"
    echo_SkyBlue ">  3. 编译安装/更新 ${RedBG} shadowsocks-libev ${Font}"
    echo_SkyBlue ">  4. 卸载 WireGuard Shadowsocks V2ray 服务程序"
    echo         "-------------------------------------------------------"
    echo_Yellow  ">  5. 显示 WireGuard V2ray 和 rc.local 配置信息"
    echo_Yellow  ">  6. 退出"
    echo_Yellow  ">  7. WireGuard 管理命令 ${RedBG} bash wgmtu "
    echo_Yellow  ">  8. 选择安装 ${GreenBG} Shadowsocks 和 V2Ray ${Yellow} 配置显示二维码"
    echo_Yellow  ">  9. 选择安装 ${RedBG} Trojan 傻瓜一键版 ${Yellow}"
    read -p "请输入数字:"  -t 30 num
    case "$num" in
        1)
        default_install
        ;;
        2)
        wget -qO- git.io/fptwc | bash
        ;;
        3)
        bash <(curl -L -s git.io/fhExJ) update
        ;;
        4)
        vps_remove
        ;;
        5)
        display_conf
        ;;
        6)
        exit 1
        ;;
        7)
        bash <(curl -L -s https://git.io/wgmtu)
        wget -O wgmtu https://git.io/wgmtu  >/dev/null 2>&1
        ;;
        8)
        bash <(curl -L -s https://git.io/v2ray.ss)
        ;;
        9)
        bash <(curl -L -s https://git.io/trojan.sh)
        ;;
        *)
        default_install
        ;;
        esac
}

# 显示文字颜色
Green="\033[32m"  && Red="\033[31m" && GreenBG="\033[42;37m" && RedBG="\033[41;37m"
Font="\033[0m"  && Yellow="\033[0;33m" && SkyBlue="\033[0;36m"

echo_SkyBlue(){
    echo -e "${SkyBlue}$1${Font}"
}
echo_Yellow(){
    echo -e "${Yellow}$1${Font}"
}
echo_GreenBG(){
    echo -e "${GreenBG}$1${Font}"
}

# 安装 wg ss v2 脚本开始菜单和必要的wget和curl工具
wget_curl
start_menu

