From 7a45632e0b05caec2d9b63e9535ad2e183e91fbf Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Tue, 26 Sep 2023 10:28:21 -0700 Subject: [PATCH] add new wp-verify-checksums.sh script --- bin/wp-verify-checksums.sh | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 bin/wp-verify-checksums.sh diff --git a/bin/wp-verify-checksums.sh b/bin/wp-verify-checksums.sh new file mode 100755 index 0000000..af88478 --- /dev/null +++ b/bin/wp-verify-checksums.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# +# wordpress-tools +# https://git.stack-source.com/msb/wordpress-tools +# Copyright (c) 2023 Matthew Saunders Brown \ +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# must be root, will su to vhost users for wp cron runs +if [ "$USER" != "root" ]; then + exec sudo $0 +fi + +# add -q command line option for quiet mode, which only outputs hard failures +# otherwise this script runs in verbose mode which shows more info, including 'File should not exist' warnings + +# create virtualhostArray listing all virtualhost on the server +cd /srv/www +virtualhostArray=(`ls -1|grep -v ^html$`) + +for VHOST in "${virtualhostArray[@]}" +do + # basic check for WP install + if [ -f /srv/www/$VHOST/html/wp-config.php ]; then + VHOST_USER=$(stat -c '%U' /srv/www/$VHOST) + # confirm that WP really is installed + if $(timeout 5 su -c "wp core is-installed --path=/srv/www/$VHOST/html/" $VHOST_USER); then + # run verify-checksums for VHOST as VHOST_USER + if [[ $1 = '-q' ]]; then + timeout 10 su -c "/usr/local/bin/wp core verify-checksums --include-root --path=/srv/www/$VHOST/html/ --quiet" $VHOST_USER + else + echo + echo "running verify-checksums on $VHOST" + timeout 10 su -c "/usr/local/bin/wp core verify-checksums --include-root --path=/srv/www/$VHOST/html/" $VHOST_USER + fi + else + echo "NOTICE: wp core is-installed failed for $VHOST (user $VHOST_USER)" + fi + fi +done