hst-install.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/bin/bash
  2. # ======================================================== #
  3. #
  4. # Hestia Control Panel Installation Routine
  5. # Automatic OS detection wrapper
  6. # https://www.hestiacp.com/
  7. #
  8. # Currently Supported Operating Systems:
  9. #
  10. # Debian 11, 12
  11. # Ubuntu 20.04, 22.04, 24.04 LTS
  12. #
  13. # ======================================================== #
  14. # Am I root?
  15. if [ "x$(id -u)" != 'x0' ]; then
  16. echo 'Error: this script can only be executed by root'
  17. exit 1
  18. fi
  19. # Check admin user account
  20. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ -z "$1" ]; then
  21. echo "Error: user admin exists"
  22. echo
  23. echo 'Please remove admin user before proceeding.'
  24. echo 'If you want to do it automatically run installer with -f option:'
  25. echo "Example: bash $0 --force"
  26. exit 1
  27. fi
  28. # Check admin group
  29. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ -z "$1" ]; then
  30. echo "Error: group admin exists"
  31. echo
  32. echo 'Please remove admin group before proceeding.'
  33. echo 'If you want to do it automatically run installer with -f option:'
  34. echo "Example: bash $0 --force"
  35. exit 1
  36. fi
  37. # Detect OS
  38. if [ -e "/etc/os-release" ] && [ ! -e "/etc/redhat-release" ]; then
  39. type=$(grep "^ID=" /etc/os-release | cut -f 2 -d '=')
  40. if [ "$type" = "ubuntu" ]; then
  41. # Check if lsb_release is installed
  42. if [ -e '/usr/bin/lsb_release' ]; then
  43. release="$(lsb_release -s -r)"
  44. VERSION='ubuntu'
  45. else
  46. echo "lsb_release is currently not installed, please install it:"
  47. echo "apt-get update && apt-get install lsb-release"
  48. exit 1
  49. fi
  50. elif [ "$type" = "debian" ]; then
  51. release=$(cat /etc/debian_version | grep -o "[0-9]\{1,2\}" | head -n1)
  52. VERSION='debian'
  53. else
  54. type="NoSupport"
  55. fi
  56. else
  57. type="NoSupport"
  58. fi
  59. no_support_message() {
  60. echo "****************************************************"
  61. echo "Your operating system (OS) is not supported by"
  62. echo "Hestia Control Panel. Officially supported releases:"
  63. echo "****************************************************"
  64. echo " Debian 11, 12"
  65. echo " Ubuntu 22.04, 24.04 LTS"
  66. echo ""
  67. exit 1
  68. }
  69. if [ "$type" = "NoSupport" ]; then
  70. no_support_message
  71. fi
  72. ensure_utf8_locale() {
  73. local locale_file="/etc/default/locale"
  74. if locale | grep -qi 'utf-8'; then
  75. return
  76. fi
  77. echo "[ * ] Enabling UTF-8 locale support via C.UTF-8"
  78. if ! locale-gen C.UTF-8; then
  79. echo "[ ! ] Failed to generate C.UTF-8 locale. Leaving existing locale untouched."
  80. return
  81. fi
  82. if ! update-locale LANG=C.UTF-8; then
  83. echo "[ ! ] Failed to update LANG in $locale_file. Leaving existing locale untouched."
  84. return
  85. fi
  86. export LANG=C.UTF-8
  87. }
  88. ensure_utf8_locale
  89. check_wget_curl() {
  90. # Check wget
  91. if [ -e '/usr/bin/wget' ]; then
  92. wget -q https://raw.githubusercontent.com/hestiacp/hestiacp/release/install/hst-install-$type.sh -O hst-install-$type.sh
  93. if [ "$?" -eq '0' ]; then
  94. bash hst-install-$type.sh $*
  95. exit
  96. else
  97. echo "Error: hst-install-$type.sh download failed."
  98. exit 1
  99. fi
  100. # fi
  101. fi
  102. # Check curl
  103. if [ -e '/usr/bin/curl' ]; then
  104. curl -s -O https://raw.githubusercontent.com/hestiacp/hestiacp/release/install/hst-install-$type.sh
  105. if [ "$?" -eq '0' ]; then
  106. bash hst-install-$type.sh $*
  107. exit
  108. else
  109. echo "Error: hst-install-$type.sh download failed."
  110. exit 1
  111. fi
  112. # fi
  113. fi
  114. }
  115. # Check for supported operating system before proceeding with download
  116. # of OS-specific installer, and throw error message if unsupported OS detected.
  117. if [[ "$release" =~ ^(11|12|22.04|24.04)$ ]]; then
  118. check_wget_curl $*
  119. else
  120. no_support_message
  121. fi
  122. exit