install_CN.sh 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 == "i386" || $arch == "i686" ]]; then
  29. arch="386"
  30. elif [[ $arch == "x86_64" || $arch == "x64" || $arch == "amd64" ]]; then
  31. arch="amd64"
  32. elif [[ $arch == "aarch64" || $arch == "arm64" ]]; then
  33. arch="arm64"
  34. elif [[ $arch == "s390x" ]]; then
  35. arch="s390x"
  36. else
  37. arch="amd64"
  38. echo -e "${red}检测架构失败,使用默认架构: ${arch}${plain}"
  39. fi
  40. echo "架构: ${arch}"
  41. if [ $(getconf WORD_BIT) != '32' ] && [ $(getconf LONG_BIT) != '64' ]; then
  42. echo "本软件不支持 32 位系统(x86),请使用 64 位系统(x86_64),如果检测有误,请联系作者"
  43. exit -1
  44. fi
  45. os_version=""
  46. # os version
  47. if [[ -f /etc/os-release ]]; then
  48. os_version=$(awk -F'[= ."]' '/VERSION_ID/{print $3}' /etc/os-release)
  49. fi
  50. if [[ -z "$os_version" && -f /etc/lsb-release ]]; then
  51. os_version=$(awk -F'[= ."]+' '/DISTRIB_RELEASE/{print $2}' /etc/lsb-release)
  52. fi
  53. if [[ x"${release}" == x"centos" ]]; then
  54. if [[ ${os_version} -le 6 ]]; then
  55. echo -e "${red}请使用 CentOS 7 或更高版本的系统!${plain}\n" && exit 1
  56. fi
  57. elif [[ x"${release}" == x"ubuntu" ]]; then
  58. if [[ ${os_version} -lt 16 ]]; then
  59. echo -e "${red}请使用 Ubuntu 16 或更高版本的系统!${plain}\n" && exit 1
  60. fi
  61. elif [[ x"${release}" == x"debian" ]]; then
  62. if [[ ${os_version} -lt 8 ]]; then
  63. echo -e "${red}请使用 Debian 8 或更高版本的系统!${plain}\n" && exit 1
  64. fi
  65. fi
  66. install_base() {
  67. if [[ x"${release}" == x"centos" ]]; then
  68. yum install wget curl tar -y
  69. else
  70. apt-get update
  71. apt install wget curl tar -y
  72. fi
  73. }
  74. #This function will be called when user installed x-ui out of sercurity
  75. config_after_install() {
  76. echo -e "${yellow}出于安全考虑,安装/更新完成后需要强制修改端口与账户密码${plain}"
  77. read -p "确认是否继续? [y/n]: " config_confirm
  78. if [[ x"${config_confirm}" == x"y" || x"${config_confirm}" == x"Y" ]]; then
  79. read -p "请设置您的账户名(如未填写则随机8位字符): " config_account
  80. [[ -z $config_account ]] && config_account=$(date +%s%N | md5sum | cut -c 1-8)
  81. echo -e "${yellow}您的账户名将设定为:${config_account}${plain}"
  82. read -p "请设置您的账户密码(如未填写则随机8位字符): " config_password
  83. [[ -z $config_password ]] && config_password=$(date +%s%N | md5sum | cut -c 1-8)
  84. echo -e "${yellow}您的账户密码将设定为:${config_password}${plain}"
  85. read -p "请设置面板访问端口(如未填写则随机端口号): " config_port
  86. [[ -z $config_port ]] && config_port=$(shuf -i 2000-65535 -n 1)
  87. until [[ -z $(ss -ntlp | awk '{print $4}' | sed 's/.*://g' | grep -w "$port") ]]; do
  88. if [[ -n $(ss -ntlp | awk '{print $4}' | sed 's/.*://g' | grep -w "$port") ]]; then
  89. echo -e "${red} $config_port ${plain} 端口已经其他程序占用,请更换面板端口号"
  90. read -p "请设置面板访问端口(如未填写则随机端口号): " config_port
  91. [[ -z $config_port ]] && config_port=$(shuf -i 2000-65535 -n 1)
  92. fi
  93. done
  94. echo -e "${yellow}您的面板访问端口将设定为:${config_port}${plain}"
  95. echo -e "${yellow}确认设定,设定中${plain}"
  96. /usr/local/x-ui/x-ui setting -username ${config_account} -password ${config_password}
  97. echo -e "${yellow}账户密码设定完成${plain}"
  98. /usr/local/x-ui/x-ui setting -port ${config_port}
  99. echo -e "${yellow}面板端口设定完成${plain}"
  100. else
  101. config_port=$(/usr/local/x-ui/x-ui setting -show | sed -n 4p | awk -F ": " '{print $2}')
  102. echo -e "${red}已取消, 所有设置项均为默认设置, 请及时修改${plain}"
  103. fi
  104. }
  105. install_x-ui() {
  106. systemctl stop x-ui
  107. cd /usr/local/
  108. if [ $# == 0 ]; then
  109. last_version=$(curl -Ls "https://api.github.com/repos/sing-web/x-ui/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
  110. if [[ ! -n "$last_version" ]]; then
  111. echo -e "${red}检测 x-ui 版本失败,可能是超出 Github API 限制,请稍后再试,或手动指定 x-ui 版本安装${plain}"
  112. exit 1
  113. fi
  114. echo -e "检测到 x-ui 最新版本:${last_version},开始安装"
  115. wget -N --no-check-certificate -O /usr/local/x-ui-linux-${arch}.tar.gz https://github.com/sing-web/x-ui/releases/download/${last_version}/x-ui-linux-${arch}.tar.gz
  116. if [[ $? -ne 0 ]]; then
  117. echo -e "${red}下载 x-ui 失败,请确保你的服务器能够下载 Github 的文件${plain}"
  118. exit 1
  119. fi
  120. else
  121. last_version=$1
  122. url="https://github.com/sing-web/x-ui/releases/download/${last_version}/x-ui-linux-${arch}.tar.gz"
  123. echo -e "开始安装 x-ui $1"
  124. wget -N --no-check-certificate -O /usr/local/x-ui-linux-${arch}.tar.gz ${url}
  125. if [[ $? -ne 0 ]]; then
  126. echo -e "${red}下载 x-ui $1 失败,请确保此版本存在${plain}"
  127. exit 1
  128. fi
  129. fi
  130. if [[ -e /usr/local/x-ui/ ]]; then
  131. rm /usr/local/x-ui/ -rf
  132. fi
  133. tar zxvf x-ui-linux-${arch}.tar.gz
  134. rm x-ui-linux-${arch}.tar.gz -f
  135. cd x-ui
  136. chmod +x x-ui bin/xray-linux-${arch}
  137. cp -f x-ui.service /etc/systemd/system/
  138. wget --no-check-certificate -O /usr/bin/x-ui https://raw.githubusercontent.com/sing-web/x-ui/main/x-ui_CN.sh
  139. chmod +x /usr/local/x-ui/x-ui.sh
  140. chmod +x /usr/bin/x-ui
  141. config_after_install
  142. #echo -e "如果是全新安装,默认网页端口为 ${green}54321${plain},用户名和密码默认都是 ${green}admin${plain}"
  143. #echo -e "请自行确保此端口没有被其他程序占用,${yellow}并且确保 54321 端口已放行${plain}"
  144. # echo -e "若想将 54321 修改为其它端口,输入 x-ui 命令进行修改,同样也要确保你修改的端口也是放行的"
  145. #echo -e ""
  146. #echo -e "如果是更新面板,则按你之前的方式访问面板"
  147. #echo -e ""
  148. systemctl daemon-reload
  149. systemctl enable x-ui
  150. systemctl start x-ui
  151. systemctl stop warp-go >/dev/null 2>&1
  152. wg-quick down wgcf >/dev/null 2>&1
  153. ipv4=$(curl -s4m8 ip.p3terx.com -k | sed -n 1p)
  154. ipv6=$(curl -s6m8 ip.p3terx.com -k | sed -n 1p)
  155. systemctl start warp-go >/dev/null 2>&1
  156. wg-quick up wgcf >/dev/null 2>&1
  157. echo -e "${green}x-ui ${last_version}${plain} 安装完成,面板已启动"
  158. echo -e ""
  159. echo -e "x-ui 管理脚本使用方法: "
  160. echo -e "----------------------------------------------"
  161. echo -e "x-ui - 显示管理菜单 (功能更多)"
  162. echo -e "x-ui start - 启动 x-ui 面板"
  163. echo -e "x-ui stop - 停止 x-ui 面板"
  164. echo -e "x-ui restart - 重启 x-ui 面板"
  165. echo -e "x-ui status - 查看 x-ui 状态"
  166. echo -e "x-ui enable - 设置 x-ui 开机自启"
  167. echo -e "x-ui disable - 取消 x-ui 开机自启"
  168. echo -e "x-ui log - 查看 x-ui 日志"
  169. echo -e "x-ui update - 更新 x-ui 面板"
  170. echo -e "x-ui install - 安装 x-ui 面板"
  171. echo -e "x-ui uninstall - 卸载 x-ui 面板"
  172. echo -e "----------------------------------------------"
  173. echo ""
  174. if [[ -n $ipv4 ]]; then
  175. echo -e "${yellow}面板IPv4访问地址为:${plain} ${green}http://$ipv4:$config_port ${plain}"
  176. fi
  177. if [[ -n $ipv6 ]]; then
  178. echo -e "${yellow}面板IPv6访问地址为:${plain} ${green}http://[$ipv6]:$config_port ${plain}"
  179. fi
  180. echo -e "请自行确保此端口没有被其他程序占用,${yellow}并且确保${plain} ${red} $config_port ${plain} ${yellow}端口已放行${plain}"
  181. }
  182. echo -e "${green}开始安装${plain}"
  183. install_base
  184. install_x-ui $1