Archive for March, 2009

I updated my gcc formatting php script.

Tuesday, March 24th, 2009

A while ago I wrote a script that formats gcc output to link errors back into TM. I updated that script with support for warnings and added some cool looking construction theme colors for the errors and warnings. Have a look see.

Formatting gcc and g++ output for TextMate.

WordPress Auto-Update Script For A Linux Server

Monday, March 16th, 2009

I wrote a little update script for my server to auto update my wordpress installation and figured it might help some other people as well. To use it you simply supply as arguments to the script three things:

1. the directory where your wordpress install lives
2. the name of the backups you’d like to create for that directory
3. the version of the wordpress install you’d like to upgrade to

For example, on my server I use this command to update my wp version:

sudo ./updateWordpress.sh /path/to/wordpress/installation efnx 2.7.1
[enter password]
[watch output]

done!

Here is the code to my script:

#!/bin/bash
DIR2UPDATE=$1
NAME=$2
VERSION=$3

echo "Beginning update of $DIR2UPDATE to version $VERSION..."

if [ -d wordpress_svn ]
then
    day=`date | cut -d" " -f3`
    tme=`date | cut -d" " -f4`
    hour=`echo ${tme} | cut -d":" -f1`

    fileday=`ls -lh | grep wordpress_svn | cut -c 37-39`
    filehour=`ls -lh | grep wordpress_svn | cut -c 40-41`

    if [ ${fileday} != ${day} ]; then
            echo "SVN directory not up to date, [ file's date ${fileday} != today ${day} ] deleting and updating"
        rm -rf wordpress_svn/*
        cd wordpress_svn
            svn co http://svn.automattic.com/wordpress/tags/${VERSION} .
    else
            if [ "$filehour" != "$hour" ]; then
                    echo "SVN directory not up to date, [ file's hour ${filehour} != now ${hour} ] deleting and updating"
                rm -rf wordpress_svn/*
                    cd wordpress_svn
                    svn co http://svn.automattic.com/wordpress/tags/${VERSION} .
        else
                    echo "SVN directory is up to date, skipping update"
                cd wordpress_svn
        fi
    fi

else
    echo "Creating new svn directory and checking out version $VERSION...";
    mkdir wordpress_svn;
    cd wordpress_svn;
    svn co http://svn.automattic.com/wordpress/tags/${VERSION} .;
fi

cd ..

if [ -d wordpress_int ]
then
    echo "Removing old intermediate container...";
    rm -rf wordpress_int;
fi

echo "Creating new intermediate container..."
mkdir wordpress_int
echo "Moving version $VERSION files into intermediate container..."
cp -rpf wordpress_svn/* wordpress_int

echo "Moving config and custom files from $NAME into intermediate container..."

cp -p ${DIR2UPDATE}/wp-config.php wordpress_int
cp -rpf ${DIR2UPDATE}/wp-content/* wordpress_int/wp-content/
cp -p ${DIR2UPDATE}/.htaccess wordpress_int
echo 'Updating svn for wp-content'
svn update wordpress_int

echo "Backing up $DIR2UPDATE..."
mkdir ${NAME}_backup
#mv -f ${DIR2UPDATE}/* ${NAME}_backup   # if you'd like to mv instead of cp
cp -rpf ${DIR2UPDATE}/* ${NAME}_backup
tar -czvf ${NAME}_backup.tar.gz ${NAME}_backup
rm -rf ${NAME}_backup

echo 'Removing svn data from intermediate container...'
rm -rf `find wordpress_int/ -type d -name .svn`
echo "Moving intermediate container contents to $DIR2UPDATE..."
cp -rpf wordpress_int/* ${DIR2UPDATE}

Or you can just download the script here [rightclick + 'save as']->
updateWordpress.sh


Follow me on GitHub
Follow me on Google+
Follow me on Twitter