outline-x-ui


SUBMITTED BY: suzi125

DATE: Sept. 3, 2023, 7:14 p.m.

UPDATED: Sept. 3, 2023, 7:31 p.m.

FORMAT: Text only

SIZE: 7.8 kB

HITS: 385

  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 with 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. else
  33. arch="amd64"
  34. echo -e "${red}fail to check system arch,will use default arch here: ${arch}${plain}"
  35. fi
  36. echo "架构: ${arch}"
  37. if [ $(getconf WORD_BIT) != '32' ] && [ $(getconf LONG_BIT) != '64' ]; then
  38. echo "x-ui dosen't support 32bit(x86) system,please use 64 bit operating system(x86_64) instead,if there is something wrong,plz let me know"
  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}please use CentOS 7 or higher version${plain}\n" && exit 1
  52. fi
  53. elif [[ x"${release}" == x"ubuntu" ]]; then
  54. if [[ ${os_version} -lt 16 ]]; then
  55. echo -e "${red}please use Ubuntu 16 or higher version${plain}\n" && exit 1
  56. fi
  57. elif [[ x"${release}" == x"debian" ]]; then
  58. if [[ ${os_version} -lt 8 ]]; then
  59. echo -e "${red}please use Debian 8 or higher version${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. #This function will be called when user installed x-ui out of sercurity
  70. config_after_install() {
  71. echo -e "${yellow}Install/update finished need to modify panel settings out of security${plain}"
  72. read -p "are you continue,if you type n will skip this at this time[y/n]": config_confirm
  73. if [[ x"${config_confirm}" == x"y" || x"${config_confirm}" == x"Y" ]]; then
  74. read -p "please set up your username:" config_account
  75. echo -e "${yellow}your username will be:${config_account}${plain}"
  76. read -p "please set up your password:" config_password
  77. echo -e "${yellow}your password will be:${config_password}${plain}"
  78. read -p "please set up the panel port:" config_port
  79. echo -e "${yellow}your panel port is:${config_port}${plain}"
  80. echo -e "${yellow}initializing,wait some time here...${plain}"
  81. /usr/local/x-ui/x-ui setting -username ${config_account} -password ${config_password}
  82. echo -e "${yellow}account name and password set down!${plain}"
  83. /usr/local/x-ui/x-ui setting -port ${config_port}
  84. echo -e "${yellow}panel port set down!${plain}"
  85. else
  86. echo -e "${red}cancel...${plain}"
  87. if [[ ! -f "/etc/x-ui/x-ui.db" ]]; then
  88. local usernameTemp=$(head -c 6 /dev/urandom | base64)
  89. local passwordTemp=$(head -c 6 /dev/urandom | base64)
  90. local portTemp=$(echo $RANDOM)
  91. /usr/local/x-ui/x-ui setting -username ${usernameTemp} -password ${passwordTemp}
  92. /usr/local/x-ui/x-ui setting -port ${portTemp}
  93. echo -e "this is a fresh installation,will generate random login info for security concerns:"
  94. echo -e "###############################################"
  95. echo -e "${green}user name:${usernameTemp}${plain}"
  96. echo -e "${green}user password:${passwordTemp}${plain}"
  97. echo -e "${red}web port:${portTemp}${plain}"
  98. echo -e "###############################################"
  99. echo -e "${red}if you forgot your login info,you can type x-ui and then type 7 to check after installation${plain}"
  100. else
  101. echo -e "${red} this is your upgrade,will keep old settings,if you forgot your login info,you can type x-ui and then type 7 to check${plain}"
  102. fi
  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/FranzKafkaYu/x-ui/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
  110. if [[ ! -n "$last_version" ]]; then
  111. echo -e "${red}refresh x-ui version failed,it may due to Github API restriction,please try it later${plain}"
  112. exit 1
  113. fi
  114. echo -e "get x-ui latest version succeed:${last_version},begin to install..."
  115. wget -N --no-check-certificate -O /usr/local/x-ui-linux-${arch}-english.tar.gz https://github.com/FranzKafkaYu/x-ui/releases/download/${last_version}/x-ui-linux-${arch}-english.tar.gz
  116. if [[ $? -ne 0 ]]; then
  117. echo -e "${red}dowanload x-ui failed,please be sure that your server can access Github{plain}"
  118. exit 1
  119. fi
  120. else
  121. last_version=$1
  122. url="https://github.com/FranzKafkaYu/x-ui/releases/download/${last_version}/x-ui-linux-${arch}-english.tar.gz"
  123. echo -e "begin to install x-ui v$1 ..."
  124. wget -N --no-check-certificate -O /usr/local/x-ui-linux-${arch}-english.tar.gz ${url}
  125. if [[ $? -ne 0 ]]; then
  126. echo -e "${red}dowanload x-ui v$1 failed,please check the verison exists${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}-english.tar.gz
  134. rm x-ui-linux-${arch}-english.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/FranzKafkaYu/x-ui/main/x-ui_en.sh
  139. chmod +x /usr/local/x-ui/x-ui_en.sh
  140. chmod +x /usr/bin/x-ui
  141. config_after_install
  142. systemctl daemon-reload
  143. systemctl enable x-ui
  144. systemctl start x-ui
  145. echo -e "${green}x-ui v${last_version}${plain} install finished,it is working now..."
  146. echo -e ""
  147. echo -e "x-ui control menu usages: "
  148. echo -e "----------------------------------------------"
  149. echo -e "x-ui - Enter control menu"
  150. echo -e "x-ui start - Start x-ui "
  151. echo -e "x-ui stop - Stop x-ui "
  152. echo -e "x-ui restart - Restart x-ui "
  153. echo -e "x-ui status - Show x-ui status"
  154. echo -e "x-ui enable - Enable x-ui on system startup"
  155. echo -e "x-ui disable - Disable x-ui on system startup"
  156. echo -e "x-ui log - Check x-ui logs"
  157. echo -e "x-ui update - Update x-ui "
  158. echo -e "x-ui install - Install x-ui "
  159. echo -e "x-ui uninstall - Uninstall x-ui "
  160. echo -e "x-ui geo - Update geo data"
  161. echo -e "----------------------------------------------"
  162. }
  163. echo -e "${green}
  164. ❤❤Thanks U For Using❤❤
  165. Telegram Account>>>https://t.me/HWY16 ${plain}"
  166. install_base
  167. install_x-ui $1"

comments powered by Disqus