del.inc 2.9 KB

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