#!/bin/bash

# 更改主机名称
# 需要收件执行linux-init
OSS_PATH_PREFIX=https://b2.107421.xyz
V2RAY_INSTALL_SCRIPT_PATH=$OSS_PATH_PREFIX/v2ray-install.sh
V2RAY_FILE_OSS_PATH=$OSS_PATH_PREFIX/v2ray-linux-64_v4.32.1.zip


install_v2ray() {
    echo "开始下载需要的v2ray文件！"
    wget $V2RAY_INSTALL_SCRIPT_PATH
    wget $V2RAY_FILE_OSS_PATH

    echo ""
    echo "开始执行V2ray的安装工作"

    echo "y
    " | bash ./v2ray-install.sh --local v2ray-linux-64_v4.32.1.zip

    echo "v2ray安装成功！"

}

modify_sock5_v2ray_config() {

  echo "开始修改V2ray的配置，为socks5的形式！"

  cat >/usr/local/etc/v2ray/config.json <<EOF
{
  "inbounds": [
    {
      "protocol": "socks",
      "port": 28888,
      "listen": "0.0.0.0",
      "settings": {
        "auth": "password",
        "accounts": [
          {
            "user": "zeaslity",
            "pass": "lovemm.23"
          }
        ],
        "udp": true,
        "userLevel": 0
      }
    },
    {
      "protocol": "socks",
      "port": 58889,
      "listen": "0.0.0.0",
      "settings": {
        "auth": "noauth",
        "udp": true,
        "userLevel": 0
      }
    }
  ],
  "dns": {
    "network": "udp",
    "address": "223.5.5.5",
    "port": 53
  },
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {}
    }
  ]
}
EOF

  echo ""
  systemctl restart v2ray

  echo "v2ray配置完成！ 请检查v2ray端口的开放情况！"
  echo "$(netstat -ntlp | grep 2888)"
}

main() {
  install_v2ray

  modify_sock5_v2ray_config
}

main
