Last active
June 19, 2017 20:28
-
-
Save MiteshShah/cd4d86cbdfa60a069aa9 to your computer and use it in GitHub Desktop.
Update Multiple WordPress
This file contains 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 | |
# Define Variables | |
WEB_ROOT=/var/www | |
WEB_ROOT_PREFIX=htdocs | |
WEB_ROOT_GROUP=www-data | |
WP_UPDATE_LOGS=/var/log/setup/wp-update.log | |
# Capture Errors | |
function OwnError() { | |
echo "[ `date` ] $(tput setaf 1)$@$(tput sgr0)" | tee -ai $WP_UPDATE_LOGS | |
exit $2 | |
} | |
function WP_UPDATE() { | |
# Check WP-CLI is installed or not | |
wp --allow-root --info 2> /dev/null | |
if [ $? -ne 0 ]; then | |
echo "Downloading WP-CLI, Please wait..." | |
wget -qO /usr/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \ | |
|| OwnError "Unable to download WP-CLI, exit status = " $? | |
# Executable permission | |
chmod a+x /usr/bin/wp || OwnError "Unable to set executable permission for wp-cli, exit status = " $? | |
fi | |
# Check For WordPress | |
for i in $(ls $WEB_ROOT);do | |
if [ -d $WEB_ROOT/$i/$WEB_ROOT_PREFIX/wp-admin ]; then | |
echo "Found wp-admin at $WEB_ROOT/$i/$WEB_ROOT_PREFIX/wp-admin" | |
cd $WEB_ROOT/$i/$WEB_ROOT_PREFIX/ | |
WEB_ROOT_OWNER=$(stat -c '%U' $WEB_ROOT/$i/$WEB_ROOT_PREFIX/wp-admin) | |
echo "PWD = $PWD" | tee -ai $WP_UPDATE_LOGS | |
echo "WEB_ROOT = $WEB_ROOT" | tee -ai $WP_UPDATE_LOGS | |
echo "WEB_ROOT_PREFIX = $WEB_ROOT_PREFIX" | tee -ai $WP_UPDATE_LOGS | |
echo "WEB_ROOT_OWNER = $WEB_ROOT_OWNER" | tee -ai $WP_UPDATE_LOGS | |
echo "WEB_ROOT_GROUP = $WEB_ROOT_GROUP" | tee -ai $WP_UPDATE_LOGS | |
# Update WordPress | |
wp --allow-root core update | |
# Update WordPress Plugins | |
wp --allow-root plugin update --all | |
# Update WordPress Themes | |
wp --allow-root theme update --all | |
# Change Permission | |
chown -R $WEB_ROOT_OWNER:$WEB_ROOT_GROUP $WEB_ROOT/$i/$WEB_ROOT_PREFIX | |
chmod -R 775 $WEB_ROOT/$i/$WEB_ROOT_PREFIX/wp-content/uploads/ | |
fi | |
done | |
} | |
tail -n1 /var/log/rsnapshot.log | grep "completed successfully" | |
if [ $? -eq 0 ]; then | |
WP_UPDATE | tee -ai $WP_UPDATE_LOGS | |
else | |
grep $(date +"%Y-%m-%d") /var/log/rsnapshot.log | mail -s "Local backup on $(hostname) failed WP_UPDATE failed" Mr.Miteshah@gmail.com | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment