del.inc 3.2 KB

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