del.inc 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh
  2. hestia_module_php_del() {
  3. source $HESTIA/bin/module/func.inc
  4. source $HESTIA/bin/module/php/func.inc
  5. module_installed=$(hestia_module_isinstalled php)
  6. if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
  7. echo "PHP module is not installed. See 'hestia module info php'."
  8. exit 1
  9. fi
  10. module_variant=$(hestia_module_getvariant php)
  11. if [ "$module_variant" != 'php-fpm' ] && [ ! "$param_force" ]; then
  12. echo "The installed PHP module is not FPM. See 'hestia module info php'."
  13. exit 1
  14. fi
  15. # PHP version is first parameter
  16. param_ver="$1"
  17. if [ ! $param_ver ]; then
  18. echo "You must specify PHP version"
  19. exit 1
  20. fi
  21. # Verify php version format
  22. if [[ ! $param_ver =~ ^[0-9]\.[0-9]+ ]]; then
  23. echo "The PHP version format is invalid, it should look like [0-9].[0-9]..."
  24. exit
  25. fi
  26. # Check version is supported
  27. php_version=''
  28. for ver in $PHP_SUPPORTED_VERSIONS; do
  29. if [ "$param_ver" == "$ver" ]; then
  30. php_version=$param_ver
  31. break;
  32. fi
  33. done
  34. if [ ! "$php_version" ]; then
  35. echo "PHP version $param_ver is not supported."
  36. exit 1
  37. fi
  38. php_withoutdot=${php_version//.}
  39. php_version_present=$(osal_kv_read_bool $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present")
  40. if [ ! "$php_version_present" ] && [ ! "$param_force" ]; then
  41. echo "PHP version ${php_version} is not present. See 'hestia module php list'."
  42. exit 1
  43. fi
  44. # Perform verification if read-only mode is enabled
  45. check_hestia_demo_mode
  46. echo "Removing PHP version ${php_version}..."
  47. php_etc_folder=$(osal_multiphp_etc_folder $php_version)
  48. hestia_config_backup 'php-del' $php_etc_folder \
  49. $HESTIA/data/templates/web/php-fpm/PHP-${php_version/\./_}.tpl
  50. php_prefix=$(osal_multiphp_php_package_prefix $php_version)
  51. mph="$php_prefix-mbstring $php_prefix-bcmath $php_prefix-cli $php_prefix-curl
  52. $php_prefix-fpm $php_prefix-gd $php_prefix-intl $php_prefix-mysql
  53. $php_prefix-soap $php_prefix-xml $php_prefix-zip $php_prefix-mbstring
  54. $php_prefix-json $php_prefix-bz2 $php_prefix-pspell"
  55. # Check is version is 7.1 or below to add mcrypt
  56. if [[ `echo "$php_version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
  57. mph="$mph $php_prefix-mcrypt"
  58. fi
  59. # Purge php packages
  60. osal_service_stop $php_prefix-fpm > /dev/null 2>&1
  61. osal_service_disable $php_prefix-fpm > /dev/null 2>&1
  62. osal_execute_with_spinner osal_package_remove $mph
  63. # Check if uninstallation was sucessfully
  64. if [ $(osal_multiphp_fpm_isinstalled $php_version) ]; then
  65. echo "Uninstallation failed, please run the following command manualy for debuging:"
  66. echo "$OSAL_CMD_PACKAGE_MANAGER (remove or purge) ${mph//\\n/ \\}"
  67. fi
  68. # Cleanup files and folders
  69. [ -f $HESTIA/data/templates/web/php-fpm/PHP-${php_version/\./_}.tpl ] && rm -f $HESTIA/data/templates/web/php-fpm/PHP-${php_version/\./_}.tpl
  70. [[ -d "$php_etc_folder" ]] && rm -rf "$php_etc_folder"
  71. osal_kv_write $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present" '0'
  72. log_history "removed php $phpversion" '' 'admin'
  73. exit 0
  74. }