v-delete-web-php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # Check if php version exists
  26. if [ ! -f "$php_fpm" ] && [ ! -f "$HESTIA/data/templates/$WEB_SYSTEM/PHP-$version.sh" ]; then
  27. echo "Version is not installed..."
  28. exit
  29. fi
  30. #----------------------------------------------------------#
  31. # Action #
  32. #----------------------------------------------------------#
  33. mph="php$version-mbstring php$version-bcmath php$version-cli php$version-curl
  34. php$version-fpm php$version-gd php$version-intl php$version-mysql
  35. php$version-soap php$version-xml php$version-zip php$version-mbstring
  36. php$version-json php$version-bz2 php$version-pspell"
  37. # Check is version is 7.1 or below to add mcrypt
  38. if [[ `echo "$version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
  39. mph="$mph php$version-mcrypt"
  40. fi
  41. # Purge php packages
  42. apt-get -y purge $mph > /dev/null 2>&1 &
  43. BACK_PID=$!
  44. # Check if package removal is done, print a spinner
  45. echo "Removing PHP-$version, please wait..."
  46. spinner="/-\|"
  47. spin_i=1
  48. while kill -0 $BACK_PID > /dev/null 2>&1 ; do
  49. printf "\b${spinner:spin_i++%${#spinner}:1}"
  50. sleep 0.5
  51. done
  52. # Do a blank echo to get the \n back
  53. echo
  54. # Check if installation was sucessfully
  55. if [ -f "$php_fpm" ]; then
  56. echo "Uninstallation failed, please run the following command manualy for debuging:"
  57. echo "apt-get purge $mph"
  58. fi
  59. # Remove backend template
  60. rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
  61. #----------------------------------------------------------#
  62. # Hestia #
  63. #----------------------------------------------------------#
  64. # Logging
  65. log_history "removed php $version"
  66. log_event "$OK" "$ARGUMENTS"
  67. exit