-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript-patch-all-tnc-toolbox.sh
54 lines (44 loc) · 2.67 KB
/
script-patch-all-tnc-toolbox.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Creates unrestricted cPanel API Tokens & updates the TNC Toolbox for WP
# https://github.com/The-Network-Crew/TNC-Toolbox-for-WordPress/
# (C) The Network Crew Pty Ltd - GPLv3 license enclosed
# NOTE: This script assumes a properly functional CageFS set-up on your server.
# CageFS: If you do not have this set-up, change/comment "wp" & install separately.
# fixperms: You need https://github.com/PeachFlame/cPanel-fixperms in /usr/local/sbin
# THIS SCRIPT IS TO UPDATE THE PLUGIN. For install, see the other bash script in repo.
# Between v1.0/v1.1 and v1.2, the config method changed. This script handles the update.
# Require root to run
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# Check for jq, install if not present
rpm -qa | grep -qw jq || yum -y install jq
# DOCS: wp-cli syntax is here: https://developer.wordpress.org/cli/commands/plugin/install/
for user in `\ls -A1 /var/cpanel/users/`
do
# Capture the home directory
homedir=$(getent passwd ${user} | cut -d : -f 6)
# Skip account if it isn't WordPress
if [[ ! -f ${homedir}"/public_html/wp-includes/version.php" ]] ; then
echo "SKIPPING USER: ${user} does not run WP."
continue
fi
# Update plugin, if it exists; deploy config
if [[ -d ${homedir}"/public_html/wp-content/plugins/tnc-toolbox/" ]] ; then
echo "UPDATE: tnc-toolbox present in ${user}"
su - ${user} -c "cd public_html && wp plugin update tnc-toolbox"
mkdir -p ${homedir}/public_html/wp-content/tnc-toolbox-config/
uapi --output=jsonpretty --user=${user} Tokens revoke name='TNC-TOOLBOX'
uapi --output=jsonpretty --user=${user} Tokens revoke name='TNC-WP-TOOLBOX'
uapi --output=jsonpretty --user=${user} Tokens create_full_access name='TNC-TOOLBOX' | jq -r '.result.data.token' > ${homedir}/public_html/wp-content/tnc-toolbox-config/cpanel-api-key
echo ${user} > ${homedir}/public_html/wp-content/tnc-toolbox-config/cpanel-username
hostname -f > ${homedir}/public_html/wp-content/tnc-toolbox-config/server-hostname
fixperms -a ${user}
chmod 0600 ${homedir}/public_html/wp-content/tnc-toolbox-config/*
echo -n $(tr -d "\n" < ${homedir}/public_html/wp-content/tnc-toolbox-config/cpanel-username) > ${homedir}/public_html/wp-content/tnc-toolbox-config/cpanel-username
echo -n $(tr -d "\n" < ${homedir}/public_html/wp-content/tnc-toolbox-config/cpanel-api-key) > ${homedir}/public_html/wp-content/tnc-toolbox-config/cpanel-api-key
echo -n $(tr -d "\n" < ${homedir}/public_html/wp-content/tnc-toolbox-config/server-hostname) > ${homedir}/public_html/wp-content/tnc-toolbox-config/server-hostname
chown ${user}:${user} -R ${homedir}/public_html/wp-content/tnc-toolbox-config/
fi
done