install 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #!/bin/bash
  2. ######################################################################
  3. # Auto Install & Optimize LEMP Stack on Ubuntu/centOS #
  4. # #
  5. # Author: Sanvv - HOSTVN Technical #
  6. # Website: https://hostvn.vn #
  7. # #
  8. # Please do not remove copyright. Thank! #
  9. # Please do not copy under any circumstance for commercial reason! #
  10. ######################################################################
  11. rm -rf install
  12. # Set Color
  13. RED='\033[0;31m'
  14. NC='\033[0m'
  15. OS=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
  16. SCRIPT_LINK="https://scripts.hostvn.net/${OS}"
  17. OS_LIST="centos ubuntu debian almalinux"
  18. RAM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
  19. LOW_RAM='400000'
  20. # Control Panel path
  21. CPANEL="/usr/local/cpanel/cpanel"
  22. DIRECTADMIN="/usr/local/directadmin/custombuild/build"
  23. PLESK="/usr/local/psa/version"
  24. WEBMIN="/etc/init.d/webmin"
  25. SENTORA="/root/passwords.txt"
  26. HOCVPS="/etc/hocvps/scripts.conf"
  27. VPSSIM="/home/vpssim.conf"
  28. EEV3="/usr/local/bin/ee"
  29. WORDOPS="/usr/local/bin/wo"
  30. KUSANAGI="/home/kusanagi"
  31. CWP="/usr/local/cwpsrv"
  32. VESTA="/usr/local/vesta/"
  33. EEV4="/opt/easyengine"
  34. LARVPS="/etc/larvps/.info.conf"
  35. TINO="/opt/tinopanel"
  36. # Set Lang
  37. ROOT_ERR="Ban can dang nhap SSH voi user root."
  38. CANCEL_INSTALL="Huy cai dat..."
  39. RAM_NOT_ENOUGH="Canh bao: Dung luong RAM qua thap de cai Script. (It nhat 512MB)"
  40. WRONG_OS="Rat tiec he dieu hanh ban dang su dung khong duoc ho tro."
  41. OTHER_CP_EXISTS="May chu cua ban da cai dat Control Panel khac. Vui long rebuild de cai dat Script."
  42. HOSTVN_EXISTS="May chu cua ban da cai dat HOSTVN Script. Vui long rebuild neu muon cai dat lai."
  43. export LC_ALL="en_US.UTF-8"
  44. export LC_CTYPE="en_US.UTF-8"
  45. create_source_list(){
  46. if [[ "$OS" == 'ubuntu' && "${OS_VER}" == "18.04" ]]; then
  47. mv /etc/apt/sources.list /etc/apt/sources.list."$(date +%Y-%m-%d)"
  48. cat >> "/etc/apt/sources.list" << EOsource_list
  49. deb http://archive.ubuntu.com/ubuntu/ bionic main restricted
  50. deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted
  51. deb http://archive.ubuntu.com/ubuntu/ bionic universe
  52. deb http://archive.ubuntu.com/ubuntu/ bionic-updates universe
  53. deb http://archive.ubuntu.com/ubuntu/ bionic multiverse
  54. deb http://archive.ubuntu.com/ubuntu/ bionic-updates multiverse
  55. deb http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse
  56. deb http://security.ubuntu.com/ubuntu bionic-security main restricted
  57. deb http://security.ubuntu.com/ubuntu bionic-security universe
  58. deb http://security.ubuntu.com/ubuntu bionic-security multiverse
  59. EOsource_list
  60. apt update -y
  61. fi
  62. if [[ "$OS" == 'ubuntu' && "${OS_VER}" == "20.04" ]]; then
  63. mv /etc/apt/sources.list /etc/apt/sources.list."$(date +%Y-%m-%d)"
  64. cat >> "/etc/apt/sources.list" << EOsource_list
  65. deb http://archive.ubuntu.com/ubuntu/ focal main restricted
  66. deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
  67. deb http://archive.ubuntu.com/ubuntu/ focal universe
  68. deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
  69. deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
  70. deb http://archive.ubuntu.com/ubuntu/ focal multiverse
  71. deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
  72. deb http://security.ubuntu.com/ubuntu focal-security main restricted
  73. deb http://security.ubuntu.com/ubuntu focal-security universe
  74. deb http://security.ubuntu.com/ubuntu focal-security multiverse
  75. EOsource_list
  76. apt update -y
  77. fi
  78. }
  79. if [[ "$(id -u)" != "0" ]]; then
  80. printf "${RED}%s${NC}\n" "${ROOT_ERR}"
  81. printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
  82. exit
  83. fi
  84. if [[ ${RAM_TOTAL} -lt ${LOW_RAM} ]]; then
  85. printf "${RED}%s${NC}\n" "${RAM_NOT_ENOUGH}"
  86. printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
  87. exit
  88. fi
  89. if [[ -f "${CPANEL}" || -f "${DIRECTADMIN}" || -f "${PLESK}" || -f "${WEBMIN}" || -f "${SENTORA}" || -f "${HOCVPS}" || -f "${LARVPS}" ]]; then
  90. printf "${RED}%s${NC}\n" "${OTHER_CP_EXISTS}"
  91. printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
  92. exit
  93. fi
  94. if [[ -f "${VPSSIM}" || -f "${WORDOPS}" || -f "${EEV3}" || -d "${EEV4}" || -d "${VESTA}" || -d "${CWP}" || -d "${KUSANAGI}" || -d "${TINO}" ]]; then
  95. printf "${RED}%s${NC}\n" "${OTHER_CP_EXISTS}"
  96. printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
  97. exit
  98. fi
  99. if [[ -f "/var/hostvn/.hostvn.conf" ]]; then
  100. printf "${RED}%s${NC}\n" "${HOSTVN_EXISTS}"
  101. printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
  102. exit
  103. fi
  104. OS_VER=$(grep -w "VERSION_ID=" "/etc/os-release" | cut -f2 -d'=' | cut -f2 -d'"')
  105. # if [ ${OS_VER} == '8' ]; then
  106. # printf "${RED}%s${NC}\n" "Hien tai centOS 8 da khong con duoc cong ty RHEL ho tro phat trien phien ban on dinh. Vui long su dung phien ban Ubuntu 18.04 hoac 20.04"
  107. # printf "%s\n" "${RED}De biet them thong tin ban co the search Google voi tu khoa:${NC} centOS is Dead"
  108. # printf "${RED}%s${NC}\n" "Huy cai dat."
  109. # exit 0
  110. # fi
  111. if [[ " ${OS_LIST[*]} " == *" ${OS} "* ]]; then
  112. prompt_install="y"
  113. if [[ "${OS}" == "centos" ]]; then
  114. printf "${RED}%s${NC}\n" "Hien tai centOS da khong con duoc cong ty RHEL ho tro phat trien phien ban on dinh."
  115. printf "%s\n" "${RED}De biet them thong tin ban co the search Google voi tu khoa:${NC} centOS is Dead"
  116. printf "${RED}%s${NC}\n" "De VPS hoat dong on dinh khuyen nghi ban nen cai dat ban Ubuntu (18.04, 20.04) thay vi su dung ban centOS."
  117. printf "%s\n" "${RED}Huy cai dat.${NC}"
  118. exit
  119. # while true
  120. # do
  121. # read -r -p "Ban co muon tiep tuc cai dat khong ? (y/n) " prompt_install
  122. # echo
  123. # if [[ "${prompt_install}" =~ ^([yY])$ || "${prompt_install}" =~ ^([nN])$ ]]; then
  124. # break
  125. # else
  126. # printf "%s\n" "${RED}Huy cai dat.${NC}"
  127. # exit
  128. # fi
  129. # done
  130. fi
  131. if [[ "${prompt_install}" =~ ^([yY])$ ]]; then
  132. if [[ "${OS}" == "centos" || "${OS}" == "almalinux" ]]; then
  133. yum -y update
  134. yum -y install dos2unix
  135. else
  136. create_source_list
  137. apt autoremove -y
  138. apt -y install dos2unix
  139. fi
  140. curl -sO "${SCRIPT_LINK}"/"${OS}"
  141. dos2unix "${OS}"
  142. chmod +x "${OS}"
  143. bash "${OS}"
  144. fi
  145. else
  146. printf "${RED}%s${NC}\n" "${WRONG_OS}"
  147. printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
  148. exit
  149. fi