Skip to content

Commit 657a6e4

Browse files
authored
Merge pull request hestiacp#1575 from hestiacp/feature/2021-01-add-wpcli-user-account
[Feature] Download / Install wp-cli for user
2 parents 3002d0a + e59908f commit 657a6e4

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

bin/v-add-user-wp-cli

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

0 commit comments

Comments
 (0)