litespeed.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #!/bin/bash
  2. # This script looks at the user's environment, then fetches the appropriate installer for Litespeed.
  3. # Error handling, make sure we exit cleanly if something goes wrong instead of breaking the user's system.
  4. setup(){
  5. set -o errexit
  6. set -o errtrace
  7. set -o nounset
  8. set -o pipefail
  9. }
  10. # Checks for reasons running this script could be unsafe, then abort
  11. check_environment(){
  12. # Not Linux
  13. operating_system=$(uname -s)
  14. if [ ! "${operating_system}" == "Linux" ]; then
  15. echo "Fatal error: your operating system is not supported."
  16. exit 1
  17. fi
  18. # Not root
  19. if ! [ "$(id -u)" = 0 ]; then
  20. echo "Please run this script as root, or with sudo."
  21. exit 1
  22. fi
  23. # No serial no
  24. if [ $# -eq 0 ]; then
  25. echo "Please include your serial no when running this script, i.e. bash install.sh 123456789. To request a trial key, use bash install.sh TRIAL"
  26. exit 1
  27. fi
  28. # LS already installed
  29. if [ -f /usr/local/lsws/bin/lswsctrl ]; then
  30. echo "Fatal error: found Litespeed is already installed. Refusing to install a second time."
  31. exit 1
  32. fi
  33. }
  34. Base_DownloadTrialKey()
  35. {
  36. curl -s -S -o trial.key "${1}"
  37. }
  38. Base_GetTrialKey()
  39. {
  40. local LICENSE_SITE="https://license.litespeedtech.com/reseller/trial.key"
  41. local LICENSE_SITE_2="https://license2.litespeedtech.com/reseller/trial.key"
  42. if ! Base_DownloadTrialKey $LICENSE_SITE;
  43. then
  44. Base_DownloadTrialKey $LICENSE_SITE_2
  45. fi
  46. }
  47. run_installers(){
  48. # This applies to all control panels
  49. admin_pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 ; echo '')
  50. if [ -d "/etc/httpd/conf/plesk.conf.d/" ] || [ -d "/etc/apache2/plesk.conf.d/" ]; then
  51. is_plesk=1
  52. else
  53. is_plesk=0
  54. fi
  55. # cPanel is installed
  56. if [ -d "/usr/local/cpanel" ] && [ -f "./lsws.options" ]; then
  57. . ./lsws.options
  58. curl -s -S -o "lsws_whm_autoinstaller.sh" https://cpanel.litespeed.sh
  59. chmod a+x lsws_whm_autoinstaller.sh
  60. ./lsws_whm_autoinstaller.sh "$1" "${php_suexec}" "${port_offset}" "${admin_user}" "${admin_pass}" "${admin_email}" "${easyapache_integration}" "${auto_switch_to_lsws}" "${deploy_lscwp}"
  61. echo "Install finished! Your randomly generated admin password for the LiteSpeed WebAdmin interface on port 7080 is ${admin_pass}"
  62. echo "Please make sure to save this password."
  63. elif [ -d "/usr/local/cpanel" ] && [ ! -f "./lsws.options" ]; then
  64. echo "Could not find an lsws.options file. We will ask you for your preferred settings instead, but for automated bulk provisioning, you may want to exit and create an lsws.options file."
  65. read -p "Continue installer? (y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
  66. read -p "Enable PHP_SUEXEC. Run PHP processes as the account owner. Available values: 0 (off), 1 (on), and 2 (user home directory only). Default value is 2: " php_suexec
  67. php_suexec="${php_suexec:=2}"
  68. read -p "Apache port offset. Run LiteSpeed in parallel with Apache. For example, if set to 1000, Apache will listen on port 80, and LiteSpeed on 1080. If set to 0, Apache and LiteSpeed will use the same port, and LiteSpeed will not automatically start after installation. Default value is 1000: " port_offset
  69. port_offset="${port_offset:=1000}"
  70. read -p "Admin username. For accessing LiteSpeed WebAdmin console. Default value is admin: " admin_user
  71. admin_user="${admin_user:=admin}"
  72. read -p "Admin email address. Receive important server notices, such as license expiration and server core dumps. Default value is root@localhost: " admin_email
  73. admin_email="${admin_email:=root@localhost}"
  74. read -p "EasyApache integration. Automatically rebuild matching PHP for LiteSpeed under EasyApache 3. Does nothing under EasyApache 4. Available values are 1 (enable) and 0 (disable). Default value is 1: " easyapache_integration
  75. easyapache_integration="${easyapache_integration:=1}"
  76. read -p "Switch to LiteSpeed Web Server. Automatically switches at the end of the installation if the port offset is set to 0. Available values are 1 (enable) and 0 (disable). Default value is 0: " auto_switch_to_lsws
  77. auto_switch_to_lsws="${auto_switch_to_lsws:=0}"
  78. read -p "Deploy LSCWP Automatically. Scans for Wordpress Websites on server and installs LSCache Plugin on them, Automatically sets up Cache Root. Available values are 1 (enable) and 0 (disable). Default value is 0: " deploy_lscwp
  79. deploy_lscwp="${deploy_lscwp:=0}"
  80. curl -s -S -o "lsws_whm_autoinstaller.sh" https://cpanel.litespeed.sh
  81. chmod a+x lsws_whm_autoinstaller.sh
  82. ./lsws_whm_autoinstaller.sh "$1" "${php_suexec}" "${port_offset}" "${admin_user}" "${admin_pass}" "${admin_email}" "${easyapache_integration}" "${auto_switch_to_lsws}" "${deploy_lscwp}"
  83. echo "Install finished! Your randomly generated admin password for the LiteSpeed WebAdmin interface on port 7080 is ${admin_pass}"
  84. echo "Please make sure to save this password."
  85. # Plesk is installed
  86. elif [[ $is_plesk -eq 1 ]] && [[ -f "./lsws.options" ]]; then
  87. . ./lsws.options
  88. curl -s -S -o "lsws_plesk_autoinstaller.sh" https://plesk.litespeed.sh
  89. chmod a+x lsws_plesk_autoinstaller.sh
  90. ./lsws_plesk_autoinstaller.sh "$1" "${php_suexec}" "${port_offset}" "${admin_user}" "${admin_pass}" "${admin_email}" "${auto_switch_php}" "${auto_switch_to_lsws}"
  91. echo "Install finished! Your randomly generated admin password for the LiteSpeed WebAdmin interface on port 7080 is ${admin_pass}"
  92. echo "Please make sure to save this password."
  93. elif [[ $is_plesk -eq 1 ]] && [[ ! -f "./lsws.options" ]]; then
  94. echo "Could not find an lsws.options file. We will ask you for your preferred settings instead, but for automated bulk provisioning, you may want to exit and create an lsws.options file."
  95. read -p "Continue installer? (y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
  96. read -p "Enable PHP_SUEXEC. Run PHP processes as the account owner. Available values: 0 (off), 1 (on), and 2 (user home directory only). Default value is 2: " php_suexec
  97. php_suexec="${php_suexec:=2}"
  98. read -p "Apache port offset. Run LiteSpeed in parallel with Apache. For example, if set to 1000, Apache will listen on port 80, and LiteSpeed on 1080. If set to 0, Apache and LiteSpeed will use the same port, and LiteSpeed will not automatically start after installation. Default value is 1000: " port_offset
  99. port_offset="${port_offset:=2}"
  100. read -p "Admin username. For accessing LiteSpeed WebAdmin console. Default value is admin: " admin_user
  101. admin_user="${admin_user:=admin}"
  102. read -p "Admin email address. Receive important server notices, such as license expiration and server core dumps. Default value is root@localhost: " admin_email
  103. admin_email="${admin_email:=root@localhost}"
  104. read -p "Switch PHP Handlers. Automatically switch PHP handlers for users and/or subscriptions inside of Plesk. Available values: 0 (No change), 1 (Switch just for users), 2 (Switch just for subscriptions), 3 (Switch for both users and subscriptions). Default value is 0: " auto_switch_php
  105. auto_switch_php="${auto_switch_php:=0}"
  106. read -p "Switch to LiteSpeed Web Server. Automatically switches at the end of the installation if the port offset is set to 0. Available values are 1 (enable) and 0 (disable): " auto_switch_to_lsws
  107. curl -s -S -o "lsws_plesk_autoinstaller.sh" https://plesk.litespeed.sh
  108. chmod a+x lsws_plesk_autoinstaller.sh
  109. ./lsws_plesk_autoinstaller.sh "$1" "${php_suexec}" "${port_offset}" "${admin_user}" "${admin_pass}" "${admin_email}" "${auto_switch_php}" "${auto_switch_to_lsws}"
  110. echo "Install finished! Your randomly generated admin password for the LiteSpeed WebAdmin interface on port 7080 is ${admin_pass}"
  111. echo "Please make sure to save this password."
  112. # DirectAdmin is installed
  113. # For DirectAdmin, we don't have a similar installer as cPanel, but we can do everything using the command line rather than GUI.
  114. # Customization is more bare-bones in the absense of an autoinstaller like cPanel has.
  115. elif [ -d "/usr/local/directadmin" ] && [ -f "./lsws.options" ]; then
  116. . ./lsws.options
  117. cd /usr/local/directadmin/custombuild
  118. ./build update
  119. ./build set webserver litespeed
  120. ./build set mod_ruid2 no
  121. if [[ $1 == "TRIAL" ]] || [[ $1 == "trial" ]] ; then
  122. ./build set litespeed_serialno trial
  123. else
  124. ./build set litespeed_serialno $1
  125. fi
  126. ./build set php1_mode lsphp
  127. ./build set php1_release ${php_version_default}
  128. ./build set php2_mode lsphp
  129. ./build set php2_release ${php_version_second}
  130. ./build set php3_mode lsphp
  131. ./build set php3_release ${php_version_third}
  132. ./build set php4_mode lsphp
  133. ./build set php4_release ${php_version_fourth}
  134. ./build litespeed
  135. ./build php n
  136. echo "Install finished! Your randomly generated admin password for the LiteSpeed WebAdmin interface on port 7080 is `grep -m1 '^litespeedadmin=' | cut -d= -f2`"
  137. echo "Please make sure to save this password."
  138. elif [ -d "/usr/local/directadmin" ] && [ ! -f "./lsws.options" ]; then
  139. echo "Could not find an lsws.options file. We will ask you for your preferred settings instead, but for automated bulk provisioning, you may want to exit and create an lsws.options file."
  140. read -p "Continue installer? (y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
  141. read -p "Which PHP version would be the default? You'll get the option to install more PHP versions below. Available values: 5.6, 7.0, 7.1, 7.2, 7.3. Default value is 7.2: " php_version_default
  142. php_version_default="${php_version_default:=7.2}"
  143. read -p "Would you like to install second PHP version? Available values: 5.6, 7.0, 7.1, 7.2, 7.3, no . Default value is no, Just press enter or write no(without caps) to not install a second php version: " php_version_second
  144. php_version_second="${php_version_second:=no}"
  145. read -p "Would you like to install third PHP version? Available values: 5.6, 7.0, 7.1, 7.2, 7.3, no . Default value is no, Just press enter or write no(without caps) to not install a third php version: " php_version_third
  146. php_version_third="${php_version_third:=no}"
  147. read -p "Would you like to install fourth PHP version? Available values: 5.6, 7.0, 7.1, 7.2, 7.3, no . Default value is no, Just press enter or write no(without caps) to not install a fourth php version: " php_version_fourth
  148. php_version_fourth="${php_version_fourth:=no}"
  149. cd /usr/local/directadmin/custombuild
  150. ./build update
  151. ./build set webserver litespeed
  152. ./build set mod_ruid2 no
  153. if [[ $1 == "TRIAL" ]] || [[ $1 == "trial" ]] ; then
  154. ./build set litespeed_serialno trial
  155. else
  156. ./build set litespeed_serialno $1
  157. fi
  158. ./build set php1_mode lsphp
  159. ./build set php1_release ${php_version_default}
  160. ./build set php2_mode lsphp
  161. ./build set php2_release ${php_version_second}
  162. ./build set php3_mode lsphp
  163. ./build set php3_release ${php_version_third}
  164. ./build set php4_mode lsphp
  165. ./build set php4_release ${php_version_fourth}
  166. ./build litespeed
  167. ./build php n
  168. echo "Install finished! Your randomly generated admin password for the LiteSpeed WebAdmin interface on port 7080 is `grep -m1 '^litespeedadmin=' | cut -d= -f2`"
  169. echo "Please make sure to save this password."
  170. # No control panel
  171. else
  172. latest_version=$(curl -s -S http://update.litespeedtech.com/ws/latest.php | head -n 1 | sed -nre 's/^[^0-9]*(([0-9]+\.)*[0-9]+).*/\1/p') # 5.3.1, 6.0.1, etc
  173. major_version=$(echo "${latest_version}" | cut -c 1) # 5, 6, etc
  174. bitness=$(uname -m)
  175. if [ "${bitness}" == "i686" ]; then
  176. bitness="i386"
  177. fi
  178. rm -f lsws-latest.tar.gz # Clean up in case of old installs
  179. rm -rf "lsws-${latest_version}" # Clean up in case of old installs
  180. curl -s -S -o "lsws-latest.tar.gz" https://www.litespeedtech.com/packages/"${major_version}".0/lsws-"${latest_version}"-ent-"${bitness}"-linux.tar.gz
  181. tar -xzf "lsws-latest.tar.gz"
  182. cd "lsws-${latest_version}"
  183. if [[ "${1}" == "TRIAL" ]] || [[ "${1}" == "trial" ]] ; then
  184. Base_GetTrialKey
  185. else
  186. echo "${1}" > serial.no
  187. fi
  188. bash "./install.sh"
  189. fi
  190. }
  191. main(){
  192. setup
  193. check_environment "$@"
  194. run_installers "$@"
  195. exit 0
  196. }
  197. main "$@"