v-add-user-wp-cli 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_DIR" ]; then
  37. echo "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. #----------------------------------------------------------#
  47. # Hestia #
  48. #----------------------------------------------------------#
  49. # Logging
  50. $BIN/v-log-action "$user" "Info" "Plugins" "WP-CLI support enabled."
  51. log_event "$OK" "$ARGUMENTS"
  52. exit