WP finder

This bit of code will find all of the wordpress installs and the version and put it in a file for you to use with the WP SVN Updater.

You are free to use the code, but leave my name as the author, and let me know if you update or improve it.

[code lang=”bash”]
#!/bin/bash
#——————————————————-#
# Locate all installs of WordPress on the server.
# Supply the path to save the file. File does not need to exist.
# @Author: Ammon Shepherd
# @Date: 08.03.10
VERSION=”1.3.1″
# CHANGE LOG:
# 03.17.09 – Added check so that program can’t overwrite itself…
# cause I just did that… Changed some echoed text.
# 07.23.10 – Added check for repository. Changed layout of report.
# 08.03.10 – Added totals to the bottom of the file.
# – Added BASH check for unset variables and return values
#——————————————————————————#

set -e # End the script if any statement returns a non-true return value
set -u # End script if an unset variable is encountered.

echo -n “Type in the full path to a file to store the installs: ”
read -e VERSIONFILE

# Don’t let the script over write itself
if [ $VERSIONFILE == $0 ]; then
echo -n “Attempting to use the program file name, type a different file: ”
read -e VERSIONFILE
fi

if [ -f $VERSIONFILE ]; then
echo -n “Overwrite existing file $VERSIONFILE? (y/n): ”
read answer
if [ $answer = “y” ];then
rm $VERSIONFILE
else
echo -n “Enter new name for file: ”
read -e VERSIONFILE
fi
fi

fullpath=( $(locate ‘wp-includes/version.php’) )

svninstalls=”
notsvn=”
count=”
for path in ${fullpath[*]}
do
if [ -f $path ]; then
directory=`ls $path | sed -e “s|wp-includes/version.php||”`
echo $directory >> $VERSIONFILE
version=`grep “wp_version = ” $path | cut -d” ” -f3 | sed -e “s|’||g” -e “s|;||g”`
# Check to see if it’s an .svn install
if [[ -d $directory/.svn && -f $directory/wp-config.php ]]; then
repo=`svn info $directory | grep URL`
(( svninstalls++ ))
else
repo=”Not an SVN repository”
(( notsvn++ ))
fi
echo -e “\t$repo\n” >> $VERSIONFILE
(( count++ ))
fi
done

echo ” >> $VERSIONFILE
echo ” >> $VERSIONFILE
echo “;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;” >> $VERSIONFILE
echo “; ” >> $VERSIONFILE
echo “; Total SVN Installs: $svninstalls ” >> $VERSIONFILE
echo “; Total NOT SVN Installs: $notsvn ” >> $VERSIONFILE
echo “; ” >> $VERSIONFILE
echo “; Total WordPress Installs: $count ” >> $VERSIONFILE
echo “; ” >> $VERSIONFILE
echo “;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;” >> $VERSIONFILE

#edit the wp-versions file
sed -i -e “s/^/;/” $VERSIONFILE

echo “WordPress installs and versions are located in the file ‘$VERSIONFILE'”

exit 0
[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.