mirror of
https://github.com/myvesta/vesta
synced 2025-07-05 12:36:23 -07:00
Create v-desinfect-wp
This commit is contained in:
parent
aa2f5e4fbb
commit
a8e39817fc
1 changed files with 89 additions and 0 deletions
89
bin/v-desinfect-wp
Normal file
89
bin/v-desinfect-wp
Normal file
|
@ -0,0 +1,89 @@
|
|||
#!/bin/bash
|
||||
# info: disinfect a WordPress site with several maintenance commands
|
||||
# options: DOMAIN
|
||||
|
||||
# -------------------------------------------------------- #
|
||||
# variables and checks #
|
||||
# -------------------------------------------------------- #
|
||||
|
||||
if [ "$(whoami)" != "root" ]; then
|
||||
echo "You must be root to run this command."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# make sure all Vesta helper scripts are reachable
|
||||
export PATH="/usr/local/vesta/bin:$PATH"
|
||||
source /etc/profile
|
||||
|
||||
domain="$1"
|
||||
if [ -z "$domain" ]; then
|
||||
echo "Usage: v-desinfect-wp DOMAIN"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
user=$(/usr/local/vesta/bin/v-search-domain-owner "$domain")
|
||||
if [ -z "$user" ]; then
|
||||
echo "Domain $domain does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# choose the correct admin-password script (with or without the “s”)
|
||||
if [ -x /usr/local/vesta/bin/v-change-wp-admin-pass ]; then
|
||||
admin_pass_script="/usr/local/vesta/bin/v-change-wp-admin-pass"
|
||||
elif [ -x /usr/local/vesta/bin/v-change-wp-admins-pass ]; then
|
||||
admin_pass_script="/usr/local/vesta/bin/v-change-wp-admins-pass"
|
||||
else
|
||||
admin_pass_script=""
|
||||
fi
|
||||
|
||||
# absolute paths to maintenance scripts, in desired order
|
||||
declare -a tasks=(
|
||||
"/usr/local/vesta/bin/v-change-db-password-to-wordpress"
|
||||
"/usr/local/vesta/bin/v-fix-wp-core"
|
||||
"/usr/local/vesta/bin/v-wf-malware-hyperscan-with-remediate"
|
||||
)
|
||||
|
||||
# append the admin script if we found one
|
||||
[ -n "$admin_pass_script" ] && tasks+=("$admin_pass_script")
|
||||
|
||||
# -------------------------------------------------------- #
|
||||
# execution strategy #
|
||||
# -------------------------------------------------------- #
|
||||
|
||||
echo
|
||||
read -r -p "Run all maintenance steps automatically? (y/n) " run_all < /dev/tty
|
||||
|
||||
if [[ "$run_all" =~ ^[Yy]$ ]]; then
|
||||
echo "Running all maintenance steps for $domain"
|
||||
automatic=true
|
||||
else
|
||||
echo
|
||||
echo "Selective mode. You will be asked for each step."
|
||||
automatic=false
|
||||
fi
|
||||
|
||||
for cmd in "${tasks[@]}"; do
|
||||
if [ ! -x "$cmd" ]; then
|
||||
echo "Command $cmd not found or not executable, skipping."
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ "$automatic" = false ]; then
|
||||
while true; do
|
||||
read -r -p "Run $(basename "$cmd") for $domain? (y/n) " yn < /dev/tty
|
||||
case "$yn" in
|
||||
[Yy]* ) break ;;
|
||||
[Nn]* ) echo "Skipping $(basename "$cmd")."; continue 2 ;;
|
||||
* ) echo "Please answer y or n." ;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "=== $(basename "$cmd") $domain ==="
|
||||
"$cmd" "$domain"
|
||||
done
|
||||
|
||||
echo
|
||||
echo "Done."
|
||||
exit 0
|
Loading…
Add table
Add a link
Reference in a new issue