Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Reiner030/046f2f6d7bceec1ab81bab36a94a6198 to your computer and use it in GitHub Desktop.
Save Reiner030/046f2f6d7bceec1ab81bab36a94a6198 to your computer and use it in GitHub Desktop.
cat /etc/cron.daily/wordpress
#!/bin/sh
set -e
WWW_USER="www-data"
WWW_PATH="/var/www"
WPCLI_UPDATE=`wp cli check-update --allow-root 2>/dev/null \
| grep -v "Success: WP-CLI is at the latest version." | wc -l`
if test $WPCLI_UPDATE -gt 0
then
wp cli update --allow-root --yes
fi
for wp_instance in `find ${WWW_PATH} -maxdepth 2 -name wp-config.php | xargs -L 1 dirname`
do
CORE_UPDATE=`sudo -u ${WWW_USER} \
wp core check-update --path=$wp_instance --field=version 2>/dev/null \
| grep -v "WordPress is at the latest version." | wc -l`
PLUGIN_UPDATES=`sudo -u ${WWW_USER} \
wp plugin status --path=$wp_instance 2>/dev/null | grep "^ U" | wc -l`
THEME_UPDATES=`sudo -u ${WWW_USER} \
wp theme status --path=$wp_instance 2>/dev/null | grep "^ U" | wc -l`
if test $CORE_UPDATE -gt 0 -o $PLUGIN_UPDATES -gt 0 -o $THEME_UPDATES -gt 0
then
echo "Updating ${}wp_instance}:"
echo
fi
if test $CORE_UPDATE -gt 0
then
sudo -u ${WWW_USER} \
wp core update --path=$wp_instance
sudo -u ${WWW_USER} \
wp core update-db --path=$wp_instance
fi
if test $PLUGIN_UPDATES -gt 0
then
sudo -u ${WWW_USER} \
wp plugin update --all --path=$wp_instance
fi
if test $THEME_UPDATES -gt 0
then
sudo -u ${WWW_USER} \
wp theme update --all --path=$wp_instance
fi
if test $CORE_UPDATE -gt 0 -o $PLUGIN_UPDATES -gt 0 -o $THEME_UPDATES -gt 0
then
echo
echo
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment