Skip to content

Instantly share code, notes, and snippets.

@laacz
Last active December 13, 2017 14:45
Show Gist options
  • Save laacz/f928f136dc417adb2543bcbcb8774d56 to your computer and use it in GitHub Desktop.
Save laacz/f928f136dc417adb2543bcbcb8774d56 to your computer and use it in GitHub Desktop.
Find ordpresses and update them (plugins too)
#!/usr/bin/env bash
#
# Script will find all wordpress installs and check if they're out of date
#
# Using wp-cli - http://wp-cli.org/
# Paths to search for wordpresses. Separated by space.
PATHS="/var/www /data/www"
# Paths to ignore (should not be checked). Separated by space.
IGNOREPATHS="/data/www/site1 /data/www/site2 "
WPCLI=/usr/local/bin/wp-cli
WORDPRESSES=$(find $PATHS -type d -name "wp-includes" -print)
# Loop through results
for WPATH in $WORDPRESSES; do
#echo $WPATH
# Strip wp-includes from path
WPATH=$(dirname $WPATH)
# If folder is excluded, continue
if [ "${IGNOREPATHS/$WPATH}" != "$IGNOREPATHS" ]; then
continue;
fi
$WPCLI --quiet --allow-root --path=$WPATH core update
if [ $? -ne 0 ]; then
echo "WHILE DOING $WPATH"
fi
$WPCLI --quiet --allow-root --path=$WPATH plugin --all update
if [ $? -ne 0 ]; then
echo "WHILE DOING $WPATH"
fi
if [ -f "$WPATH/.preserve-owner" ] ; then
OWNER=$(stat -c "%U:%G" $WPATH/.preserve-owner)
echo "Preserving owner $OWNER on $WPATH"
chown -R $OWNER $WPATH/wp-content/plugins $WPATH/wp-admin $WPATH/wp-includes $WPATH/index.php $WPATH/xmlrpc.php $WPATH/wp*.php
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment