#!/bin/sh

INSTALL_DIR=`pwd`
HORDE_VERSION=`ls horde-*.tar.gz | sed -e's/horde-\([0-9]*\.[0-9]*\.[0-9]*\).*/\1/'`

echo "Extracting packages..."
tar zxf horde-3.*.tar.gz
tar zxf imp-h3-4.*.tar.gz
tar zxf turba-h3-2.*.tar.gz
tar zxf ingo-h3-1.*.tar.gz

if [ -d /opt/horde ]; then
    echo "ERROR: /opt/horde already exists!"
    exit
fi

mv $INSTALL_DIR/horde-3.*/ /opt/horde
echo "$HORDE_VERSION" > /opt/horde/VERSION
cd /opt/horde/
mv $INSTALL_DIR/imp-h3-4.*/ /opt/horde/
ln -s imp-h3-4.* imp
mv $INSTALL_DIR/turba-h3-2.*/ /opt/horde/
ln -s turba-h3-2.* turba
mv $INSTALL_DIR/ingo-h3-1.*/ /opt/horde/
ln -s ingo-h3-1.* ingo

echo "Setting up initial config files..."
cd config
for file in *.dist; do cp -p $file `basename $file .dist`; done
cd ../imp/config
for file in *.dist; do cp -p $file `basename $file .dist`; done
cd ../../turba/config
for file in *.dist; do cp -p $file `basename $file .dist`; done
cd ../../ingo/config
for file in *.dist; do cp -p $file `basename $file .dist`; done

chown -R apache:apache /opt/horde

echo "Be sure to create a symlink to /opt/horde in the appropriate htdocs"
echo ""
echo "Horde Installation Complete."


