Created
September 10, 2019 16:32
-
-
Save MarcosBL/1c02d824ba7ad60a6e594042407fad7f to your computer and use it in GitHub Desktop.
Keep Wordpress Up to Date
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 | |
# | |
# WP-UTD | |
# WordPress Up To Date 0.1, May 25 2012 | |
# by Marcos BL; No license, feel free use it | |
# | |
# WP-UTD checks all your local WordPress installations are | |
# up-to-date and notifies you by email if a new version | |
# is available. | |
# | |
# REQUIREMENTS | |
# Local mail server, e.g. postfix, sendmail, ... | |
# Crontab if you want to do automatic checks | |
# | |
# USAGE | |
# $ ./wp-utd <NOTIFY-EMAIL> | |
# | |
# AS CRONJOB | |
# 0 6 * * * /path/to/wp-utd [email protected] | |
# | |
### Parse Parameters #################################### | |
#PATH="/bin:/sbin:/usr/bin:/usr/sbin" | |
function latest_wp() { | |
## Determine latest version | |
echo -n "Checking WP latest version... " | |
# Alternative to 'wget': curl -I "$URL" 2> /dev/null | |
LATEST_INFO=$(wget -q -O - http://api.wordpress.org/core/version-check/1.2/) | |
LATEST=$(echo "$LATEST_INFO" | tail -n 2 | head -n 1) | |
LATEST_URL=$(echo "$LATEST_INFO" | tail -n 3 | head -n 1) | |
echo "WordPress $LATEST" | |
} | |
function have_notify_email() { | |
if [ $# -le 1 ]; then | |
echo "Usage: $0 <NOTIFY-EMAIL>" | |
echo " e.g. $0 [email protected]" | |
exit 1 | |
fi | |
NOTIFY_EMAIL="$2" | |
echo "Sending notify emails to: $NOTIFY_EMAIL" | |
} | |
function we_can_email() { | |
if [ ! -x "$(which sendmail)" ]; then | |
echo "ERROR: No sendmail compatible mail server found." | |
exit 2 | |
fi | |
HOSTNAME="$(hostname)" | |
} | |
function wpcheck() { | |
WORDPRESS=${1/\/wp-includes\/version.php/} | |
VERSION_FILE="$WORDPRESS/wp-includes/version.php" | |
echo -n "Checking $WORDPRESS" | |
if [ ! -f "$VERSION_FILE" ]; then | |
echo -n " - ERROR: No WordPress installation found at $WORDPRESS" | |
fi | |
INSTALLED=$(cat "$VERSION_FILE" \ | |
| grep '\$wp_version[ ]*=' \ | |
| sed -r "s/.+'(.+)';/\1/") | |
echo -n " - WordPress $INSTALLED" | |
if [ "$INSTALLED" != "$LATEST" ]; then | |
echo -en ' \E[47;31m'"\033[1m[ Update required! ]\033[0m" | |
echo -e "To: $NOTIFY_EMAIL\nSubject: Outdated WordPress $INSTALLED at $WORDPRESS\n\n" \ | |
"The WordPress installation on host $HOSTNAME needs an update:\n\n" \ | |
" Installed Version: WordPress $INSTALLED\n" \ | |
" at: $WORDPRESS\n\n" \ | |
" Latest Version: WordPress $LATEST\n" \ | |
" Download: $LATEST_URL" \ | |
| sendmail -t "$NOTIFY_EMAIL" | |
else | |
echo -n " Up to date." | |
fi | |
echo "" | |
} | |
### Requirements ########################################### | |
have_notify_email $0 $1 | |
we_can_email | |
## Check all WP installations ################################ | |
latest_wp | |
/usr/bin/updatedb | |
LISTING=(`locate wp-includes/version.php | grep -v '/rsyncs'`) | |
echo "" | |
echo "Found ${#LISTING[*]} WP Installations:" | |
echo "" | |
for i in ${LISTING[*]} | |
do | |
wpcheck $i | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment