del.inc 3.2 KB

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