del.inc 3.0 KB

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