#!/bin/bash

# (C) 2008 Alex Günsche <http://www.zirona.com/>
# The MIT license <http://www.opensource.org/licenses/mit-license.php> applies to this file.

# Tar, zip and svn (at least client) must be available on the system.
# A copy of WP SVN trunk must be created manually before using this script.

# To have new packages created automatically once an hour,
# make this script executable and save it to /etc/cron.hourly.

BASEPATH='/path/to/work_dir/'
DL_DIR='/path/to/download_dir/'

mkdir -p $DL_DIR 2>/dev/null
cd ${BASEPATH}trunk
svn up | grep -e 'At revision' -e 'Updated to revision' | sed -e 's/[^0-9]//g' > ${DL_DIR}current_revision

cd ..
rm -rf wordpress 2>/dev/null
mkdir wordpress
cp -r trunk/* wordpress
for i in $(find wordpress/ -name '.svn'); do rm -r $i; done
tar -zcf wpsvn.tar.gz wordpress/
zip -qr wpsvn.zip wordpress/
mv wpsvn.tar.gz wpsvn.zip $DL_DIR
rm -rf ./wordpress/

cd $DL_DIR
rm -f md5sums 2>/dev/null
for i in wpsvn.tar.gz wpsvn.zip; do md5sum $i >> md5sums; done

