shell_version="1.1.3"
#对接地址
dockerurl="https://fly.nullmouse.xyz"
#对接key
dockerkey="wqdbgywdqygwdq"
#host
dockerweb="eplcgame.com"
# 获取系统
if [[ -f /etc/redhat-release ]]; then
  release="centos"
elif cat /etc/issue | grep -Eqi "debian"; then
  release="debian"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
  release="ubuntu"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
  release="centos"
elif cat /proc/version | grep -Eqi "debian"; then
  release="debian"
elif cat /proc/version | grep -Eqi "ubuntu"; then
  release="ubuntu"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
  release="centos"
else
  echo -e "${red}未检测到系统版本，请联系脚本作者！${plain}\n" && exit 1
fi
##下面是安装运行环境
if [[ x"${release}" == x"centos" ]]; then
    yum install git -y
    echo -e "${green}检测是否已安装 Docker...${plain}"
    if ! command -v docker &> /dev/null; then
        echo -e "${green}安装 Docker...${plain}"
        yum install -y yum-utils
        yum-config-manager \
          --add-repo \
          https://download.docker.com/linux/centos/docker-ce.repo
        yum install docker-ce docker-ce-cli containerd.io -y
        systemctl start docker
        systemctl enable docker
        curl -fsSL https://get.docker.com | bash -s docker
    else
        echo -e "${green}Docker 已安装！${plain}"
    fi

    docker -v

elif [[ x"${release}" == x"ubuntu" ]]; then
    apt install git -y
    echo -e "${green}检测是否已安装 Docker...${plain}"
    if ! command -v docker &> /dev/null; then
        echo -e "${green}安装 Docker...${plain}"
        curl -fsSL https://get.docker.com -o get-docker.sh
        bash get-docker.sh
        systemctl enable docker
        systemctl start docker
    else
        echo -e "${green}Docker 已安装！${plain}"
    fi

    docker -v

elif [[ x"${release}" == x"debian" ]]; then
    apt install git -y
    echo -e "${green}检测是否已安装 Docker...${plain}"
    if ! command -v docker &> /dev/null; then
        echo -e "${green}安装 Docker...${plain}"
        curl -fsSL https://get.docker.com -o get-docker.sh
        bash get-docker.sh
        systemctl enable docker
        systemctl start docker
    else
        echo -e "${green}Docker 已安装！${plain}"
    fi


    docker -v
fi
  echo -e "${green}开始安装XrayR后端...${plain}"
  read -p "请输入容器名：" dockername
  cd /etc
  mkdir $dockername
  cd /etc/$dockername
  wget -N --user-agent="vreg45rtyhg/f4tgre45g" --no-check-certificate https://7colorshell.com/shell/key/FLY/config.yml -P ./
  wget -N --user-agent="vreg45rtyhg/f4tgre45g" --no-check-certificate https://7colorshell.com/shell/key/FLY/route.json -P ./
  wget -N --user-agent="vreg45rtyhg/f4tgre45g" --no-check-certificate https://7colorshell.com/shell/key/FLY/outbound.json -P ./
  wget -N --user-agent="vreg45rtyhg/f4tgre45g" --timeout=3 --no-check-certificate https://7colorshell.com/shell/key/eplcgame_com.cert -P ./cert
  wget -N --user-agent="vreg45rtyhg/f4tgre45g" --timeout=3 --no-check-certificate https://7colorshell.com/shell/key/eplcgame_com.key -P ./cert
  sleep 5s
  file="./config.yml"
  outbound_file="./outbound.json"
  link="http://127.0.0.1:667"
  #输入信息
  read -p "请输入节点ID：" dockerid
  read -p "出口代理IP：" SocksIP
  read -p "出口端口：" SocksPort
  read -p "出口用户名：" SocksName
  read -p "出口密码：" SocksPasswd
  #写入配置文件
  sed -i "s|$link|$dockerurl|" $file
  sed -i "s|123|$dockerkey|" $file
  sed -i "s|41|$dockerid|" $file
  sed -i "s|SocksIP|$SocksIP|" $outbound_file
  sed -i "s|50101|$SocksPort|" $outbound_file
  sed -i "s|haungan150|$SocksName|" $outbound_file
  sed -i "s|QMPhRxc49f|$SocksPasswd|" $outbound_file
  docker pull ghcr.io/xrayr-project/xrayr:latest && docker run --restart=always --name $dockername -d -v /etc/$dockername/config.yml:/etc/XrayR/config.yml -v /etc/$dockername/outbound.json:/etc/XrayR/outbound.json -v /etc/$dockername/route.json:/etc/XrayR/route.json -v /etc/$dockername/cert/eplcgame_com.cert:/etc/XrayR/cert/eplcgame_com.cert -v /etc/$dockername/cert/eplcgame_com.key:/etc/XrayR/cert/eplcgame_com.key --network=host ghcr.io/xrayr-project/xrayr:latest
  docker ps