v-delete-web-php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if [ -z "$WEB_BACKEND" ]; then
  25. echo "Multiple php versions are not supported for modphp"
  26. fi
  27. # Set file locations
  28. php_fpm="/etc/init.d/php$version-fpm"
  29. # Verify php version format
  30. if [[ ! $version =~ ^[0-9]\.[0-9]+ ]]; then
  31. echo "The PHP version format is invalid, it should look like [0-9].[0-9]."
  32. echo "Example: 7.0, 7.4"
  33. exit
  34. fi
  35. # Remove backend template
  36. [ -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl ] && rm -f $HESTIA/data/templates/web/php-fpm/PHP-${version/\./_}.tpl
  37. # Check if php version exists
  38. version_check=$($HESTIA/bin/v-list-sys-php plain | grep "$version");
  39. if [ -z "$version_check" ] ; then
  40. echo "ERROR: Specified PHP version is not installed."
  41. exit "$E_INVALID";
  42. fi
  43. # Perform verification if read-only mode is enabled
  44. check_hestia_demo_mode
  45. #----------------------------------------------------------#
  46. # Action #
  47. #----------------------------------------------------------#
  48. mph="php$version-common php$version-mbstring php$version-bcmath php$version-cli php$version-curl
  49. php$version-fpm php$version-gd php$version-intl php$version-mysql
  50. php$version-soap php$version-xml php$version-zip php$version-mbstring
  51. php$version-json php$version-bz2 php$version-pspell php$version-imagick php$version-pgsql
  52. php$version-imap php$version-ldap"
  53. # Check is version is 7.1 or below to add mcrypt
  54. if [[ `echo "$version 7.2" | awk '{print ($1 < $2)}'` == 1 ]]; then
  55. mph="$mph php$version-mcrypt"
  56. fi
  57. # Purge php packages
  58. apt-get -y purge $mph > /dev/null 2>&1 &
  59. BACK_PID=$!
  60. # Check if package removal is done, print a spinner
  61. echo "Removing PHP-$version, please wait..."
  62. spinner="/-\|"
  63. spin_i=1
  64. while kill -0 $BACK_PID > /dev/null 2>&1 ; do
  65. printf "\b${spinner:spin_i++%${#spinner}:1}"
  66. sleep 0.5
  67. done
  68. # Do a blank echo to get the \n back
  69. echo
  70. # Check if installation was successfully
  71. if [ -f "$php_fpm" ]; then
  72. echo "ERROR: Uninstallation failed, please run the following command manually for debugging:"
  73. echo "apt-get purge $mph"
  74. exit 1;
  75. fi
  76. # Cleanup php folder
  77. [[ -d /etc/php/$version ]] && rm -rf "/etc/php/$version"
  78. if [ "$WEB_BACKEND" = "php-fpm" ]; then
  79. conf=$(find /etc/php* -name www.conf)
  80. # Check if www.conf exists
  81. if [ -z "$conf" ]; then
  82. # If not grab the "last php version
  83. last=$($BIN/v-list-sys-php "shell" | tail -n1);
  84. cp -f $HESTIA/install/deb/php-fpm/www.conf /etc/php/$last/fpm/pool.d/www.conf
  85. $BIN/v-restart-web-backend
  86. fi
  87. fi
  88. #----------------------------------------------------------#
  89. # Hestia #
  90. #----------------------------------------------------------#
  91. # Logging
  92. $BIN/v-log-action "system" "Info" "System" "Uninstalled PHP $version."
  93. log_event "$OK" "$ARGUMENTS"
  94. exit