Create v-desinfect-wp

This commit is contained in:
isscbta 2025-06-17 00:40:47 +02:00 committed by GitHub
parent aa2f5e4fbb
commit a8e39817fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

89
bin/v-desinfect-wp Normal file
View 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