del.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. if hestia_module_isinstalled 'php-fpm'; then
  45. hestia module php-fpm del $php_version
  46. fi
  47. php_prefix=$(osal_php_package_prefix $php_version)
  48. mph="$php_prefix-mbstring $php_prefix-bcmath $php_prefix-cli $php_prefix-curl
  49. $php_prefix-gd $php_prefix-intl $php_prefix-mysql
  50. $php_prefix-soap $php_prefix-xml $php_prefix-zip $php_prefix-mbstring
  51. $php_prefix-json $php_prefix-bz2 $php_prefix-pspell"
  52. # Check is version is 7.1 or below to add mcrypt
  53. if [[ `echo "$php_version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
  54. mph="$mph $php_prefix-mcrypt"
  55. fi
  56. # Install php packages
  57. osal_package_preinstall
  58. osal_execute_with_spinner osal_package_remove $mph
  59. # Cleanup files and folders
  60. [ -f $HESTIA/data/templates/web/php-fpm/PHP-${php_version/\./_}.tpl ] && hestia_safe_rm $HESTIA/data/templates/web/php-fpm/PHP-${php_version/\./_}.tpl
  61. [[ -d "$php_etc_folder" ]] && hestia_safe_rm "$php_etc_folder"
  62. osal_kv_write $HESTIA_CONF_MODULES/php.conf "php${php_withoutdot}_present" '0'
  63. hestia module php integrate
  64. log_history "removed php $phpversion" '' 'admin'
  65. return 0
  66. }