v-add-sys-dependencies 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # Add php dependencies to Hestia
  3. # options: [MODE]
  4. #
  5. # This function install PHPMailer and quoteshellarg as via composer
  6. #----------------------------------------------------------#
  7. # Variables & Functions #
  8. #----------------------------------------------------------#
  9. # Includes
  10. # shellcheck source=/etc/hestiacp/hestia.conf
  11. source /etc/hestiacp/hestia.conf
  12. # shellcheck source=/usr/local/hestia/func/main.sh
  13. source $HESTIA/func/main.sh
  14. # load config file
  15. source_conf "$HESTIA/conf/hestia.conf"
  16. # upgrade config file
  17. source "$HESTIA/install/upgrade/upgrade.conf"
  18. MODE=$1
  19. user="admin"
  20. PM_INSTALL_DIR="$HESTIA/web/inc"
  21. COMPOSER_BIN="$HOMEDIR/$user/.composer/composer"
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. # Checking root permissions
  26. if [ "x$(id -u)" != 'x0' ]; then
  27. echo "ERROR: v-add-sys-dependencies can be run executed only by root user"
  28. exit 10
  29. fi
  30. # Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
  31. if [ -z "$HESTIA" ]; then
  32. HESTIA="/usr/local/hestia"
  33. fi
  34. if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
  35. echo "ERROR: Environment variables not present, installation aborted."
  36. exit 2
  37. fi
  38. # Ensure that Composer is installed for the user before continuing as it is a dependency of the PHPMailer.
  39. if [ ! -f "$COMPOSER_BIN" ]; then
  40. $BIN/v-add-user-composer "$user"
  41. if [ $? -ne 0 ]; then
  42. $BIN/v-add-user-notification admin 'Composer installation failed!' '<b>Hestia will not work without Composer.</b><br><br>Please try running the installer manually from a shell session:<br>v-add-sys-phpmailer<br><br>If this continues, open an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
  43. exit 1
  44. fi
  45. fi
  46. # Perform verification if read-only mode is enabled
  47. check_hestia_demo_mode
  48. #----------------------------------------------------------#
  49. # Action #
  50. #----------------------------------------------------------#
  51. cd "$PM_INSTALL_DIR"
  52. rm --recursive --force ${PM_INSTALL_DIR}/vendor
  53. mkdir -p ${PM_INSTALL_DIR}/vendor
  54. chown $user: -R ${PM_INSTALL_DIR}/vendor
  55. openssl_installed=$(/usr/local/hestia/php/bin/php -m | grep openssl);
  56. if [ -z "$openssl_installed" ]; then
  57. COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php $COMPOSER_BIN --quiet --no-dev install
  58. else
  59. COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/local/hestia/php/bin/php $COMPOSER_BIN --quiet --no-dev install
  60. fi
  61. # Check if installation was successful, if not abort script and throw error message notification and clean-up
  62. if [ $? -ne 0 ]; then
  63. echo "ERROR: PHPMailer installation failed!"
  64. echo "Please report this to our development team:"
  65. echo "https://github.com/hestiacp/hestiacp/issues"
  66. $BIN/v-add-user-notification admin 'Hestia PHP dependencies installation failed!' 'Please report this to our development team on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
  67. # Installation failed, clean up files
  68. rm --recursive --force ${PM_INSTALL_DIR}/vendor
  69. $BIN/v-change-sys-config-value 'USE_SERVER_SMTP' 'n'
  70. $BIN/v-log-action "system" "Error" "Plugins" "PHP dependencies installation failed"
  71. exit 1
  72. fi
  73. # Set permissions
  74. chown root: -R "${PM_INSTALL_DIR}/vendor"
  75. #----------------------------------------------------------#
  76. # Logging #
  77. #----------------------------------------------------------#
  78. $BIN/v-log-action "system" "Info" "Plugins" "PHPMailer enabled (Version: $pm_v)."
  79. log_event "$OK" "$ARGUMENTS"