v-delete-web-php 3.5 KB

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