#!/bin/sh

INSTALL_DIR=`pwd`
SOFTWARE=subversion
VERSION=1.3.2

function cleanupandexit {
  echo "Installation failed.  Look above for errors."
  cd $INSTALL_DIR
  rm -rf ${SOFTWARE}-${VERSION}
  exit 1
}

tar xzf ${SOFTWARE}-${VERSION}.tar.gz
cd $INSTALL_DIR/${SOFTWARE}-${VERSION}

sed -i -e's/\(AP[RU]_VER_REGEXES="0\\\.9\\\.\[\)5\(-9\] 0\\\.9\\\.1\[0-9\] 1\\\."\)/\14\2/' configure

./configure --with-ssl --with-zlib --with-apr=/usr/bin/apr-config --with-apr-util=/usr/bin/apu-config --with-apxs=/usr/sbin/apxs --with-editor=/bin/vi --enable-swig-bindings=all || cleanupandexit

make || cleanupandexit
make install || cleanupandexit
make swig-py || cleanupandexit
make install-swig-py || cleanupandexit
make javahl || cleanupandexit
make install-javahl || cleanupandexit

if [[ -d /usr/lib/python2.3 ]]; then
  python=/usr/lib/python2.3
elif [[ -d /usr/lib/python2.2 ]]; then
  python=/usr/lib/python2.2
fi

ln -s /usr/local/lib/svn-python/svn $python/svn
ln -s /usr/local/lib/svn-python/libsvn $python/libsvn

echo ""
echo "Subversion Installation Complete"

