#!/bin/bash
# Install of Darwin Calendar Server for Ubuntu / Guadalinex (Debian)
# dependencies:
#  *  Python >= 2.4
#  *  all other commands and librararies (including svn) are installed automatically
# all stuff is put into "darwin" directory
LOGFILE=$0.log
rm $LOGFILE 2>/dev/null
# Install needed packages
packages="subversion curl libkrb5-dev krb5-config gcc python-dev python-pyopenssl python-pysqlite2 python-zopeinterface"
echo -e "\n\n\n"
echo "Installation of Darwin Calendar Server for Ubuntu/Debian stable"
echo "==============================================================="
echo "This software uses extended filesystem attributes (user_xattr)"
echo "which is available for ext3, reiserfs, xiafs and others."
echo "In most cases, this is not enabled by default, so perhaps"
echo "you have to change your /etc/fstab. (see later)" 
echo "At this point, user_xattr is not needed, so you can go ahead"
echo "and install the software."
echo -e "\n\nYou need a working Internet connection to proceed."
echo "Now we need to install some  packages."
echo "We need 'sudo' to do this."
echo "Please supply your password when asked for it."
echo -e "\nHit Enter to continue or Ctrl-C to abort..."
read
echo -e "\nNOTE: Installing/checking needed packages with 'apt-get -y install'."
echo "Packages: $packages"
sudo apt-get -y install $packages | tee -a $LOGFILE

DIR=darwin
echo -e "\nNOTE: Creating directory $DIR to put all stuff into it."
mkdir $DIR 2>/dev/null
cd $DIR

# Get source.
echo -e "\nNOTE: Checking out CalendarServer source from svn (silently)."
svn checkout http://svn.macosforge.org/repository/calendarserver/CalendarServer/trunk CalendarServer >>$LOGFILE

echo -e "\nNOTE: The first part of the installation has completed."
echo -e "\nNOTE: Now running 'CalendarServer/run -s' to install needed libraries..."
cd CalendarServer
./run -s >>$LOGFILE
if [ ! -f conf/caldavd-dev.plist ]
then
  echo -e "\nNOTE: Setting default configuration conf/caldav-dev-.plist."
  cp conf/caldavd-test.plist conf/caldavd-dev.plist
fi
echo -e "\nNOTE: The second part of the installation has completed."
echo "Check $LOGFILE for details."
echo -e "\n\n"
echo "ATTENTION: Now, change your /etc/fstab and include option "
echo "user_xattr for this filesystem if needed, e.g.:"
echo "   /dev/hda2 /home ext3 defaults,errors=remount-ro,user_xattr 0 2"
echo -e "\nReboot your system or remout the filesystem manually." 
echo "(It may be busy if you are using it.)"
echo -e "\nFinally execute 'darwin/CalendarServer/run' to run the server."
echo "You can access it with a web browser on http://localhost:8008/"
echo "Username: admin, password: admin, to access private data."
echo "See: http://trac.macosforge.org/projects/calendarserver for more information."
echo "Have fun."

