Created
April 18, 2015 23:57
-
-
Save karpstrucking/09d1e93668c69153941c to your computer and use it in GitHub Desktop.
batch WP update script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script will apply outstanding core/plugin updates for all WP installations on the server | |
# Each site will be tested after updates and, if offline as a result, the updates will be reverted | |
# The script assumes a folder structure of: /home/username/domain.com/html/ | |
# WP-CLI (http://wp-cli.org/) and git (http://git-scm.com/) are required | |
find /home/*/*/html -maxdepth 1 -type d -name wp-content | while read FindPath | |
do | |
# set some variables based on the current path | |
UserPath=${FindPath%/*/html/wp-content} | |
UserName=${UserPath#/home/} | |
DomainPath=${FindPath%/html/wp-content} | |
DomainName=${DomainPath#/home/$UserName/} | |
InstallPath="$DomainPath/html" | |
# change working directory | |
if [ -d $InstallPath ]; then | |
cd $InstallPath | |
# make a temporary backup of databse and core/plugin files | |
git init | |
wp --no-color db export | |
git add *.sql | |
git add *.php | |
git add wp-admin/ | |
git add wp-includes/ | |
git add wp-content/plugins/ | |
git commit -aqm "Before automatic core/plugin update" | |
# update WP core and all plugins | |
wp --no-color core update | |
wp --no-color plugin update --all | |
# check website and revert changes if errors | |
URL=`wp option get home` | |
/usr/bin/curl -o /dev/null --silent --fail $DomainName | |
if [ $? -gt 0 ]; then | |
git reset | |
git checkout . | |
wp --no-color db import | |
fi | |
# update file ownership for any new files | |
chown -R $UserName $InstallPath | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
interested by your script, where did you store it in your server ?