1
0

install.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/bin/bash
  2. red='\033[0;31m'
  3. green='\033[0;32m'
  4. yellow='\033[0;33m'
  5. plain='\033[0m'
  6. cur_dir=$(pwd)
  7. # check root
  8. [[ $EUID -ne 0 ]] && echo -e "${red}错误:${plain} 必须使用root用户运行此脚本!\n" && exit 1
  9. # check os
  10. if [[ -f /etc/redhat-release ]]; then
  11. release="centos"
  12. elif cat /etc/issue | grep -Eqi "debian"; then
  13. release="debian"
  14. elif cat /etc/issue | grep -Eqi "ubuntu"; then
  15. release="ubuntu"
  16. elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
  17. release="centos"
  18. elif cat /proc/version | grep -Eqi "debian"; then
  19. release="debian"
  20. elif cat /proc/version | grep -Eqi "ubuntu"; then
  21. release="ubuntu"
  22. elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
  23. release="centos"
  24. else
  25. echo -e "${red}未检测到系统版本,请联系脚本作者!${plain}\n" && exit 1
  26. fi
  27. arch=$(arch)
  28. if [[ $arch == "x86_64" || $arch == "x64" || $arch == "amd64" ]]; then
  29. arch="amd64"
  30. elif [[ $arch == "aarch64" || $arch == "arm64" ]]; then
  31. arch="arm64"
  32. else
  33. arch="amd64"
  34. echo -e "${red}检测架构失败,使用默认架构: ${arch}${plain}"
  35. fi
  36. echo "架构: ${arch}"
  37. if [ $(getconf WORD_BIT) != '32' ] && [ $(getconf LONG_BIT) != '64' ] ; then
  38. echo "本软件不支持 32 位系统(x86),请使用 64 位系统(x86_64),如果检测有误,请联系作者"
  39. exit -1
  40. fi
  41. os_version=""
  42. # os version
  43. if [[ -f /etc/os-release ]]; then
  44. os_version=$(awk -F'[= ."]' '/VERSION_ID/{print $3}' /etc/os-release)
  45. fi
  46. if [[ -z "$os_version" && -f /etc/lsb-release ]]; then
  47. os_version=$(awk -F'[= ."]+' '/DISTRIB_RELEASE/{print $2}' /etc/lsb-release)
  48. fi
  49. if [[ x"${release}" == x"centos" ]]; then
  50. if [[ ${os_version} -le 6 ]]; then
  51. echo -e "${red}请使用 CentOS 7 或更高版本的系统!${plain}\n" && exit 1
  52. fi
  53. elif [[ x"${release}" == x"ubuntu" ]]; then
  54. if [[ ${os_version} -lt 16 ]]; then
  55. echo -e "${red}请使用 Ubuntu 16 或更高版本的系统!${plain}\n" && exit 1
  56. fi
  57. elif [[ x"${release}" == x"debian" ]]; then
  58. if [[ ${os_version} -lt 8 ]]; then
  59. echo -e "${red}请使用 Debian 8 或更高版本的系统!${plain}\n" && exit 1
  60. fi
  61. fi
  62. install_base() {
  63. if [[ x"${release}" == x"centos" ]]; then
  64. yum install wget curl tar -y
  65. else
  66. apt install wget curl tar -y
  67. fi
  68. }
  69. install_x-ui() {
  70. systemctl stop x-ui
  71. cd /usr/local/
  72. if [[ -e /usr/local/x-ui/ ]]; then
  73. rm /usr/local/x-ui/ -rf
  74. fi
  75. if [ $# == 0 ] ;then
  76. last_version=$(curl -Ls "https://api.github.com/repos/sprov065/x-ui/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
  77. if [[ ! -n "$last_version" ]]; then
  78. echo -e "${red}检测 x-ui 版本失败,可能是超出 Github API 限制,请稍后再试,或手动指定 x-ui 版本安装${plain}"
  79. exit 1
  80. fi
  81. echo -e "检测到 x-ui 最新版本:${last_version},开始安装"
  82. wget -N --no-check-certificate -O /usr/local/x-ui-linux-${arch}.tar.gz https://github.com/sprov065/x-ui/releases/download/${last_version}/x-ui-linux-${arch}.tar.gz
  83. if [[ $? -ne 0 ]]; then
  84. echo -e "${red}下载 x-ui 失败,请确保你的服务器能够下载 Github 的文件${plain}"
  85. exit 1
  86. fi
  87. else
  88. last_version=$1
  89. url="https://github.com/sprov065/x-ui/releases/download/${last_version}/x-ui-linux-${arch}.tar.gz"
  90. echo -e "开始安装 x-ui v$1"
  91. wget -N --no-check-certificate -O /usr/local/x-ui-linux-${arch}.tar.gz ${url}
  92. if [[ $? -ne 0 ]]; then
  93. echo -e "${red}下载 x-ui v$1 失败,请确保此版本存在${plain}"
  94. exit 1
  95. fi
  96. fi
  97. tar zxvf x-ui-linux-${arch}.tar.gz
  98. rm x-ui-linux-${arch}.tar.gz -f
  99. cd x-ui
  100. chmod +x x-ui bin/xray-linux-${arch}
  101. cp -f x-ui.service /etc/systemd/system/
  102. systemctl daemon-reload
  103. systemctl enable x-ui
  104. systemctl start x-ui
  105. echo -e "${green}x-ui v${last_version}${plain} 安装完成,面板已启动,"
  106. echo -e ""
  107. echo -e "如果是全新安装,默认网页端口为 ${green}54321${plain},用户名和密码默认都是 ${green}admin${plain}"
  108. echo -e "请自行确保此端口没有被其他程序占用,${yellow}并且确保 54321 端口已放行${plain}"
  109. # echo -e "若想将 54321 修改为其它端口,输入 x-ui 命令进行修改,同样也要确保你修改的端口也是放行的"
  110. echo -e ""
  111. echo -e "如果是更新面板,则按你之前的方式访问面板"
  112. echo -e ""
  113. curl -o /usr/bin/x-ui -Ls https://raw.githubusercontent.com/sprov065/x-ui/master/x-ui.sh
  114. chmod +x /usr/bin/x-ui
  115. echo -e "x-ui 管理脚本使用方法: "
  116. echo -e "----------------------------------------------"
  117. echo -e "x-ui - 显示管理菜单 (功能更多)"
  118. echo -e "x-ui start - 启动 x-ui 面板"
  119. echo -e "x-ui stop - 停止 x-ui 面板"
  120. echo -e "x-ui restart - 重启 x-ui 面板"
  121. echo -e "x-ui status - 查看 x-ui 状态"
  122. echo -e "x-ui enable - 设置 x-ui 开机自启"
  123. echo -e "x-ui disable - 取消 x-ui 开机自启"
  124. echo -e "x-ui log - 查看 x-ui 日志"
  125. echo -e "x-ui v2-ui - 迁移本机器的 v2-ui 账号数据至 x-ui"
  126. echo -e "x-ui update - 更新 x-ui 面板"
  127. echo -e "x-ui install - 安装 x-ui 面板"
  128. echo -e "x-ui uninstall - 卸载 x-ui 面板"
  129. echo -e "----------------------------------------------"
  130. }
  131. echo -e "${green}开始安装${plain}"
  132. install_base
  133. install_x-ui $1