Skip to content

Instantly share code, notes, and snippets.

@danixland
Last active January 1, 2021 11:12
Show Gist options
  • Save danixland/5237608 to your computer and use it in GitHub Desktop.
Save danixland/5237608 to your computer and use it in GitHub Desktop.
A small script to manage multiple local WordPress install. This script can install a new WordPress website checking out the latest revision from trunk on the official svn server, it will also install the plugins "theme-check" and "wordpress-importer" both downloaded from svn too. The script has a function that will keep updated from svn both the…
#! /bin/bash
#### SCRIPT OPTIONS ####
# the docroot for your webserver
WEBSERVER="/home/www/htdocs"
# hidden directory inside the docroot (if you want to use another directory outside of the docroot you have to change the whole script)
BASEDIR=".base"
# where the temp files has to be stored?
TMPDIR="/tmp/wp_manager"
# if you know WordPress this is self explanatory ;)
PLUGINDIR="wp-content/plugins"
#### EXIT STATUSES ####
E_NOARGS=171
E_NONEWNAME=172
E_DIREXISTS=173
E_TMPDIREXISTS=174
# print usage instructions and exit
function usage () {
echo "USAGE:"
echo `basename $0` "-h"
echo "this shows the help and exits"; echo
echo `basename $0` "-i <new directory name>"
echo "install WordPress in a directory named 'new directory name'"; echo
echo `basename $0` "-u"
echo "updates all directories containing a WordPress install"; echo
exit $E_NOARGS
}
# update existing installs
function update_existing () {
echo "updating WordPress"
for dir in $(find $WEBSERVER -type d -maxdepth 1 -print); do
if [ -f ${dir}/wp-config.php ]; then
echo; echo "$dir sara' aggiornata"; echo
svn up ${dir}
fi
done
echo
echo "**************************************************"
echo "all existing WordPress sites have been updated"
echo "**************************************************"
sleep 1; clear
echo "**************************************************"
echo "Updating base plugins"
echo "**************************************************"
# update wordpress-importer
svn up $WEBSERVER/$BASEDIR/wordpress-importer
# update theme-check plugin
svn up $WEBSERVER/$BASEDIR/theme-check
echo "**************************************************"
echo "Exporting Updated Plugins"
echo "**************************************************"
if [ ! -d $TMPDIR ]; then
mkdir $TMPDIR
svn export $WEBSERVER/$BASEDIR/wordpress-importer $TMPDIR/wordpress-importer
svn export $WEBSERVER/$BASEDIR/theme-check $TMPDIR/theme-check
for dir in $(find $WEBSERVER -type d -maxdepth 1 -print); do
if [ -f ${dir}/wp-config.php ]; then
echo "copying wordpress-importer and theme-check to $dir"
if [ ! -d ${dir}/$PLUGINDIR/wordpress-importer ]; then
cp -r $TMPDIR/wordpress-importer ${dir}/$PLUGINDIR/
else
rm -rf ${dir}/$PLUGINDIR/wordpress-importer
cp -r $TMPDIR/wordpress-importer ${dir}/$PLUGINDIR/
fi
if [ ! -d ${dir}/$PLUGINDIR/theme-check ]; then
cp -r $TMPDIR/theme-check ${dir}/$PLUGINDIR/
else
rm -rf ${dir}/$PLUGINDIR/theme-check
cp -r $TMPDIR/theme-check ${dir}/$PLUGINDIR/
fi
fi
done
rm -rf $TMPDIR
else
echo "can't continue, $TMPDIR already existing, removing it and exiting"
rm -rf $TMPDIR
exit $E_TMPDIREXISTS
fi
exit 0
}
# install new WordPress site
function install_new () {
echo "***********************************************"
echo "You should first update your existing installs"
echo "and then install a new website, so that base"
echo "plugins are updated first"
echo "***********************************************"
if [ ! -z "$1" ]; then
dir_name=$1
if [ ! -d ${WEBSERVER}/$1 ]; then
mkdir ${WEBSERVER}/$1
cd ${WEBSERVER}/$1
svn co http://core.svn.wordpress.org/trunk/ .
cp $WEBSERVER/$BASEDIR/base-wp-config.php ./wp-config.php
cp -R $WEBSERVER/$BASEDIR/wordpress-importer/ ./wp-content/plugins/
cp -R $WEBSERVER/$BASEDIR/theme-check ./wp-content/plugins/
echo
echo "*****************************************************"
echo "new install for directory $1 done"
echo
echo "you should now edit $1/wp-config.php and run the"
echo "5 min WordPress Install routine"
echo "*****************************************************"
exit 0
else
echo "looks like a directory called $1 already exists, choose another name please. Exiting"
exit $E_DIREXISTS
fi
else
echo "I need a new name for your fresh install of WordPress, exiting"
exit $E_NONEWNAME
fi
}
# Parse the commandline options:
while getopts "i:uh:" Option
do
case $Option in
i ) install_new ${OPTARG}
;;
u ) update_existing
;;
h ) usage
;;
* ) usage
;; # default behaviour
esac
done
# End of option parsing.
shift $(($OPTIND - 1))
# $1 now references the first non option item supplied on the command line
# if one exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment