v-add-user-wp-cli 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/bash
  2. # info: add wp-cli for a user
  3. # options: USER
  4. #
  5. # example: v-add-user-wp-cli user
  6. #
  7. # This function adds support for wp-cli to the user account
  8. #----------------------------------------------------------#
  9. # Variables & Functions #
  10. #----------------------------------------------------------#
  11. # Argument definition
  12. user=$1
  13. if [ -z "$HESTIA" ]; then
  14. HESTIA="/usr/local/hestia"
  15. fi
  16. # shellcheck source=/etc/hestiacp/hestia.conf
  17. source /etc/hestiacp/hestia.conf
  18. # shellcheck source=/usr/local/hestia/func/main.sh
  19. source $HESTIA/func/main.sh
  20. # load config file
  21. source_conf "$HESTIA/conf/hestia.conf"
  22. #----------------------------------------------------------#
  23. # Verifications #
  24. #----------------------------------------------------------#
  25. check_args '1' "$#" 'USER'
  26. is_format_valid 'user'
  27. is_object_valid 'user' 'USER' "$user"
  28. is_object_unsuspended 'user' 'USER' "$user"
  29. # Perform verification if read-only mode is enabled
  30. check_hestia_demo_mode
  31. #----------------------------------------------------------#
  32. # Action #
  33. #----------------------------------------------------------#
  34. WPCLI_DIR="/home/$user/.wp-cli"
  35. WPCLI_BIN="$WPCLI_DIR/wp"
  36. if [ -f "$WPCLI_BIN" ]; then
  37. check_result "$E_EXISTS" "For user name '$user' WP-CLI already available!"
  38. exit
  39. fi
  40. [ -z "$(readlink -m "$WPCLI_DIR" | egrep "^$HOMEDIR/$user/")" ] && check_result "$E_FORBIDEN" "Path outside of user homedir (WP Cli dir)"
  41. [ -z "$(readlink -m "$WPCLI_BIN" | egrep "^$HOMEDIR/$user/")" ] && check_result "$E_FORBIDEN" "Path outside of user homedir (WP Cli bin)"
  42. mkdir -p "$WPCLI_DIR"
  43. chown $user:$user "$WPCLI_DIR"
  44. user_exec wget --tries=3 --timeout=15 --read-timeout=15 --waitretry=3 --no-dns-cache --quiet -O "$WPCLI_BIN" https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  45. user_exec chmod +x "$WPCLI_BIN"
  46. user_exec echo -e "#add wp-cli alias for user\nalias wp='php $WPCLI_BIN'" >> ~/.bashrc
  47. #----------------------------------------------------------#
  48. # Hestia #
  49. #----------------------------------------------------------#
  50. # Logging
  51. $BIN/v-log-action "$user" "Info" "Plugins" "WP-CLI support enabled."
  52. log_event "$OK" "$ARGUMENTS"
  53. exit