Skip to content

Commit 7eab4dc

Browse files
committed
Download wp-cli and add it to a user account
(Same as v-add-user-composer does)
1 parent 760b3d1 commit 7eab4dc

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

bin/v-add-user-wp-cli

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# info: add wp-cli for a user
3+
# options: USER
4+
# labels: hestia
5+
#
6+
# example: v-add-user-wp-cli user
7+
#
8+
# The function adds support for wp-cli to the user account
9+
10+
#----------------------------------------------------------#
11+
# Variable&Function #
12+
#----------------------------------------------------------#
13+
14+
# Argument definition
15+
user=$1
16+
17+
if [ -z "$HESTIA" ]; then
18+
HESTIA="/usr/local/hestia"
19+
fi
20+
source $HESTIA/func/main.sh
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
check_args '1' "$#" 'USER'
27+
is_format_valid 'user'
28+
is_object_valid 'user' 'USER' "$user"
29+
is_object_unsuspended 'user' 'USER' "$user"
30+
31+
[ -z "$HOMEDIR" ] && check_result $E_NOTEXIST "Hestia environment vars not present"
32+
33+
# Perform verification if read-only mode is enabled
34+
check_hestia_demo_mode
35+
36+
#----------------------------------------------------------#
37+
# Action #
38+
#----------------------------------------------------------#
39+
40+
WPCLI_DIR="/home/$user/.wp"
41+
WPCLI_BIN="$WPCLI_DIR/wp"
42+
WPCLICACHE_DIR="/home/$user/.wp-cli"
43+
44+
if [ -f "$WPCLI_DIR" ]; then
45+
echo "WP-CLI already available"
46+
exit
47+
fi
48+
49+
[ -z "$(readlink -m "$WPCLI_DIR" | egrep "^$HOMEDIR/$user/")" ] && check_result $E_FORBIDEN "Path outside of user homedir (WP Cli dir)"
50+
[ -z "$(readlink -m "$WPCLI_BIN" | egrep "^$HOMEDIR/$user/")" ] && check_result $E_FORBIDEN "Path outside of user homedir (WP Cli bin)"
51+
52+
mkdir -p "$WPCLI_DIR"
53+
chown $user:$user "$WPCLI_DIR"
54+
55+
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
56+
user_exec chmod +x $WPCLI_BIN
57+
58+
#----------------------------------------------------------#
59+
# Hestia #
60+
#----------------------------------------------------------#
61+
62+
# Logging
63+
log_history "Enabled wp-cli for user $user"
64+
log_event "$OK" "$ARGUMENTS"
65+
66+
exit

0 commit comments

Comments
 (0)