v-delete-web-php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/bin/bash
  2. # info: delete php fpm version
  3. # options: VERSION
  4. # labels: hestia
  5. #
  6. # example: v-delete-web-php 7.3
  7. #
  8. # The function checks and delete a fpm php version if not used by any domain.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. version=$1
  14. # Includes
  15. # shellcheck source=/usr/local/hestia/func/main.sh
  16. source $HESTIA/func/main.sh
  17. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  18. source $HESTIA/conf/hestia.conf
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. check_args '1' "$#" 'VERSION'
  23. # Set file locations
  24. php_fpm="/etc/init.d/php$version-fpm"
  25. # Verify php version format
  26. if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
  27. echo "The PHP version format is invalid, it should look like [0-9].[0-9]."
  28. echo "Example: 7.0, 7.4"
  29. exit
  30. fi
  31. # Remove backend template
  32. [ -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl ] && rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
  33. # Check if php version exists
  34. if [ ! -f "$php_fpm" ] && [ ! -f "$HESTIA/data/templates/$WEB_SYSTEM/PHP-$version.sh" ]; then
  35. echo "ERROR: Specified PHP version is not installed."
  36. exit
  37. fi
  38. # Perform verification if read-only mode is enabled
  39. check_hestia_demo_mode
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. mph="php$version-common php$version-mbstring php$version-bcmath php$version-cli php$version-curl
  44. php$version-fpm php$version-gd php$version-intl php$version-mysql
  45. php$version-soap php$version-xml php$version-zip php$version-mbstring
  46. php$version-json php$version-bz2 php$version-pspell php$version-imagick php$version-pgsql
  47. php$version-imap php$version-ldap"
  48. # Check is version is 7.1 or below to add mcrypt
  49. if [[ `echo "$version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
  50. mph="$mph php$version-mcrypt"
  51. fi
  52. # Purge php packages
  53. apt-get -y purge $mph > /dev/null 2>&1 &
  54. BACK_PID=$!
  55. # Check if package removal is done, print a spinner
  56. echo "Removing PHP-$version, please wait..."
  57. spinner="/-\|"
  58. spin_i=1
  59. while kill -0 $BACK_PID > /dev/null 2>&1 ; do
  60. printf "\b${spinner:spin_i++%${#spinner}:1}"
  61. sleep 0.5
  62. done
  63. # Do a blank echo to get the \n back
  64. echo
  65. # Check if installation was successfully
  66. if [ -f "$php_fpm" ]; then
  67. echo "ERROR: Uninstallation failed, please run the following command manually for debugging:"
  68. echo "apt-get purge $mph"
  69. exit 1;
  70. fi
  71. # Cleanup php folder
  72. [[ -d /etc/php/$version ]] && rm -rf "/etc/php/$version"
  73. if [ "$WEB_BACKEND" = "php-fpm" ]; then
  74. # Check if www.conf is still missing
  75. if [ ! -f "/etc/php/*/fpm/pool.d/www.conf" ]; then
  76. # If not grab the "last php version
  77. last=$($HESTIA/bin/v-list-sys-php "shell" | tail -n1);
  78. cp -f $HESTIA/install/deb/php-fpm/www.conf /etc/php/$last/fpm/pool.d/www.conf
  79. $HESTIA/bin/v-restart-web-backend
  80. fi
  81. fi
  82. #----------------------------------------------------------#
  83. # Hestia #
  84. #----------------------------------------------------------#
  85. # Logging
  86. $BIN/v-log-action "system" "Info" "System" "Uninstalled PHP $version."
  87. log_event "$OK" "$ARGUMENTS"
  88. exit