v-delete-web-php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # info: delete php fpm version
  3. # options: VERSION
  4. #
  5. # The function checks and delete a fpm php version if not used by any domain.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. version=$1
  11. # Includes
  12. source $HESTIA/func/main.sh
  13. source $HESTIA/conf/hestia.conf
  14. #----------------------------------------------------------#
  15. # Verifications #
  16. #----------------------------------------------------------#
  17. check_args '1' "$#" 'VERSION'
  18. # Set file locations
  19. php_fpm="/etc/init.d/php$version-fpm"
  20. # Verify php version format
  21. if [[ ! $version =~ ^[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. # Remove backend template
  26. [ -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl ] && rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
  27. # Check if php version exists
  28. if [ ! -f "$php_fpm" ] && [ ! -f "$HESTIA/data/templates/$WEB_SYSTEM/PHP-$version.sh" ]; then
  29. echo "Version is not installed..."
  30. exit
  31. fi
  32. # Perform verification if read-only mode is enabled
  33. check_hestia_demo_mode
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. mph="php$version-mbstring php$version-bcmath php$version-cli php$version-curl
  38. php$version-fpm php$version-gd php$version-intl php$version-mysql
  39. php$version-soap php$version-xml php$version-zip php$version-mbstring
  40. php$version-json php$version-bz2 php$version-pspell"
  41. # Check is version is 7.1 or below to add mcrypt
  42. if [[ `echo "$version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
  43. mph="$mph php$version-mcrypt"
  44. fi
  45. # Purge php packages
  46. apt-get -y purge $mph > /dev/null 2>&1 &
  47. BACK_PID=$!
  48. # Check if package removal is done, print a spinner
  49. echo "Removing PHP-$version, please wait..."
  50. spinner="/-\|"
  51. spin_i=1
  52. while kill -0 $BACK_PID > /dev/null 2>&1 ; do
  53. printf "\b${spinner:spin_i++%${#spinner}:1}"
  54. sleep 0.5
  55. done
  56. # Do a blank echo to get the \n back
  57. echo
  58. # Check if installation was sucessfully
  59. if [ -f "$php_fpm" ]; then
  60. echo "Uninstallation failed, please run the following command manualy for debuging:"
  61. echo "apt-get purge $mph"
  62. fi
  63. # Cleanup php folder
  64. [[ -d /etc/php/$version ]] && rm -rf "/etc/php/$version"
  65. #----------------------------------------------------------#
  66. # Hestia #
  67. #----------------------------------------------------------#
  68. # Logging
  69. log_history "removed php $version" '' 'admin'
  70. log_event "$OK" "$ARGUMENTS"
  71. exit