install.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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}Fatal error:${plain} Please run this script with root privilege \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} Check system OS failed, please contact the author! ${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. elif [[ $arch == "s390x" ]]; then
  33. arch="s390x"
  34. else
  35. arch="amd64"
  36. echo -e "${red} Failed to check system arch, will use default arch: ${arch}${plain}"
  37. fi
  38. echo "arch: ${arch}"
  39. if [ $(getconf WORD_BIT) != '32' ] && [ $(getconf LONG_BIT) != '64' ]; then
  40. echo "x-ui dosen't support 32-bit(x86) system, please use 64 bit operating system(x86_64) instead, if there is something wrong, please get in touch with me!"
  41. exit -1
  42. fi
  43. os_version=""
  44. # os version
  45. if [[ -f /etc/os-release ]]; then
  46. os_version=$(awk -F'[= ."]' '/VERSION_ID/{print $3}' /etc/os-release)
  47. fi
  48. if [[ -z "$os_version" && -f /etc/lsb-release ]]; then
  49. os_version=$(awk -F'[= ."]+' '/DISTRIB_RELEASE/{print $2}' /etc/lsb-release)
  50. fi
  51. if [[ x"${release}" == x"centos" ]]; then
  52. if [[ ${os_version} -le 6 ]]; then
  53. echo -e "${red} Please use CentOS 7 or higher ${plain}\n" && exit 1
  54. fi
  55. elif [[ x"${release}" == x"ubuntu" ]]; then
  56. if [[ ${os_version} -lt 16 ]]; then
  57. echo -e "${red} Please use Ubuntu 16 or higher ${plain}\n" && exit 1
  58. fi
  59. elif [[ x"${release}" == x"debian" ]]; then
  60. if [[ ${os_version} -lt 8 ]]; then
  61. echo -e "${red} Please use Debian 8 or higher ${plain}\n" && exit 1
  62. fi
  63. fi
  64. install_base() {
  65. if [[ x"${release}" == x"centos" ]]; then
  66. yum install wget curl tar -y
  67. else
  68. apt install wget curl tar -y
  69. fi
  70. }
  71. #This function will be called when user installed x-ui out of sercurity
  72. config_after_install() {
  73. echo -e "${yellow}Install/update finished! For security it's recommended to modify panel settings ${plain}"
  74. read -p "Do you want to continue with the modification [y/n]? ": config_confirm
  75. if [[ x"${config_confirm}" == x"y" || x"${config_confirm}" == x"Y" ]]; then
  76. read -p "Please set up your username:" config_account
  77. echo -e "${yellow}Your username will be:${config_account}${plain}"
  78. read -p "Please set up your password:" config_password
  79. echo -e "${yellow}Your password will be:${config_password}${plain}"
  80. read -p "Please set up the panel port:" config_port
  81. echo -e "${yellow}Your panel port is:${config_port}${plain}"
  82. echo -e "${yellow}Initializing, please wait...${plain}"
  83. /usr/local/x-ui/x-ui setting -username ${config_account} -password ${config_password}
  84. echo -e "${yellow}Account name and password set successfully!${plain}"
  85. /usr/local/x-ui/x-ui setting -port ${config_port}
  86. echo -e "${yellow}Panel port set successfully!${plain}"
  87. else
  88. echo -e "${red}Canceled, will use the default settings.${plain}"
  89. fi
  90. }
  91. install_x-ui() {
  92. systemctl stop x-ui
  93. cd /usr/local/
  94. if [ $# == 0 ]; then
  95. last_version=$(curl -Ls "https://api.github.com/repos/mhsanaei/3x-ui/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
  96. if [[ ! -n "$last_version" ]]; then
  97. echo -e "${red}Failed to fetch x-ui version, it maybe due to Github API restrictions, please try it later${plain}"
  98. exit 1
  99. fi
  100. echo -e "Got x-ui latest version: ${last_version}, beginning the installation..."
  101. wget -N --no-check-certificate -O /usr/local/x-ui-linux-${arch}.tar.gz https://github.com/mhsanaei/3x-ui/releases/download/${last_version}/x-ui-linux-${arch}.tar.gz
  102. if [[ $? -ne 0 ]]; then
  103. echo -e "${red}Downloading x-ui failed, please be sure that your server can access Github ${plain}"
  104. exit 1
  105. fi
  106. else
  107. last_version=$1
  108. url="https://github.com/mhsanaei/3x-ui/releases/download/${last_version}/x-ui-linux-${arch}.tar.gz"
  109. echo -e "Begining to install x-ui $1"
  110. wget -N --no-check-certificate -O /usr/local/x-ui-linux-${arch}.tar.gz ${url}
  111. if [[ $? -ne 0 ]]; then
  112. echo -e "${red}Download x-ui $1 failed,please check the version exists${plain}"
  113. exit 1
  114. fi
  115. fi
  116. if [[ -e /usr/local/x-ui/ ]]; then
  117. rm /usr/local/x-ui/ -rf
  118. fi
  119. tar zxvf x-ui-linux-${arch}.tar.gz
  120. rm x-ui-linux-${arch}.tar.gz -f
  121. cd x-ui
  122. chmod +x x-ui bin/xray-linux-${arch}
  123. cp -f x-ui.service /etc/systemd/system/
  124. wget --no-check-certificate -O /usr/bin/x-ui https://raw.githubusercontent.com/mhsanaei/3x-ui/main/x-ui.sh
  125. chmod +x /usr/local/x-ui/x-ui.sh
  126. chmod +x /usr/bin/x-ui
  127. config_after_install
  128. #echo -e "If it is a new installation, the default web port is ${green}2053${plain}, The username and password are ${green}admin${plain} by default"
  129. #echo -e "Please make sure that this port is not occupied by other procedures,${yellow} And make sure that port 2053 has been released${plain}"
  130. # echo -e "If you want to modify the 2053 to other ports and enter the x-ui command to modify it, you must also ensure that the port you modify is also released"
  131. #echo -e ""
  132. #echo -e "If it is updated panel, access the panel in your previous way"
  133. #echo -e ""
  134. systemctl daemon-reload
  135. systemctl enable x-ui
  136. systemctl start x-ui
  137. echo -e "${green}x-ui ${last_version}${plain} installation finished, it is running now..."
  138. echo -e ""
  139. echo -e "x-ui control menu usages: "
  140. echo -e "----------------------------------------------"
  141. echo -e "x-ui - Enter Admin menu"
  142. echo -e "x-ui start - Start x-ui"
  143. echo -e "x-ui stop - Stop x-ui"
  144. echo -e "x-ui restart - Restart x-ui"
  145. echo -e "x-ui status - Show x-ui status"
  146. echo -e "x-ui enable - Enable x-ui on system startup"
  147. echo -e "x-ui disable - Disable x-ui on system startup"
  148. echo -e "x-ui log - Check x-ui logs"
  149. echo -e "x-ui update - Update x-ui"
  150. echo -e "x-ui install - Install x-ui"
  151. echo -e "x-ui uninstall - Uninstall x-ui"
  152. echo -e "----------------------------------------------"
  153. }
  154. echo -e "${green}Running...${plain}"
  155. install_base
  156. install_x-ui $1