Basic Davical Setup Script

This is a basic bash script for a sample setup of DAViCal with apache2 and postgres. You will have to provide a virtual host file named "davical" in the same folder. If you have SSL enabled in the virtual host file it will be enabled in apache and certificates are created it a certain folder with a certain prefix.

The bash script

 * 1) ! /bin/bash


 * 1) This software licenced with the MIT license as follows.
 * 2) Copyright (C) by >
 * 3) Permission is hereby granted, free of charge, to any person obtaining a copy
 * 4) of this software and associated documentation files (the "Software"), to deal
 * 5) in the Software without restriction, including without limitation the rights
 * 6) to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * 7) copies of the Software, and to permit persons to whom the Software is
 * 8) furnished to do so, subject to the following conditions:
 * 9) The above copyright notice and this permission notice shall be included in
 * 10) all copies or substantial portions of the Software.
 * 11) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * 12) IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * 13) FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * 14) AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * 15) LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * 16) OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * 17) THE SOFTWARE.
 * 1) FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * 2) AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * 3) LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * 4) OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * 5) THE SOFTWARE.

if [ ! $(id -u) -eq 0 ]; then echo "Must be run as root." >&2	exit 1 fi

DAVICAL_SOURCE='deb http://debian.mcmillan.net.nz/debian lenny awm' TMP_FOLDER='/tmp/davical' VHOST_FILE_NAME='davical' SSL_DIR='/etc/apache2/ssl' SSL_PREFIX='server'

echo -e "This will install DAViCal for Debian with all depending software - if needed - in a basic fashion. Please make sure to have the appropriate virtual host file (named \"$VHOST_FILE_NAME\") in the same folder as this install script. \nProceed? [y/n]"

read ok

if [ $ok != "y" -a $ok != "Y" ]; then exit 2 fi

if [ -d $TMP_FOLDER ]; then echo "Temporary folder already exists." else mkdir $TMP_FOLDER echo "Creating temporary folder for the installation at $TMP_FOLDER." fi

echo "Looking for the DAViCal source in your /etc/apt/sources.list"

grep "$DAVICAL_SOURCE" /etc/apt/sources.list > /dev/null

if [ $? -eq 1 ]; then echo "Adding \"$DAVICAL_SOURCE\" to the sources." echo -e "\n#Davical source\n$DAVICAL_SOURCE" >> /etc/apt/sources.list echo "Updating." apt-get update else echo "Davical Source already in the sources.list." fi

echo "Installing packages for Davical, Apache2, PHP5 and Postgres now. If something is already installed it will be skipped."

apt-get install apache2 libapache2-mod-php5 postgresql davical

if [ ! $? -eq 0 ]; then echo "An error occured when installing software from repos. Aborting." exit 1 fi

echo "Looking for your pg_hba.conf in /etc/postgresql/."

find /etc/postgresql/ -name "pg_hba.conf" > $TMP_FOLDER/find_result

if [ $(wc -l $TMP_FOLDER/find_result | cut -d " " -f 1) -eq 0 ]; then echo "No pg_hba.conf found in /etc/postgresql/. Must be edited manually." else if [ $(wc -l $TMP_FOLDER/find_result | cut -d " " -f 1) -gt 1 ]; then echo "More than one pg_hba.conf found in /etc/postgresql/. Must be edited manually." else grep davical $(cat $TMP_FOLDER/find_result) if [ $? -eq 0 ]; then echo "The pg_hba.conf seems to contain davical configurations already. Skipping all database actions now. FAILED." else cp $(cat $TMP_FOLDER/find_result) $TMP_FOLDER/pg_hba.conf.old echo -e "# Davical configuration\nlocal\tdavical\tdavical_app\ttrust\nlocal\tdavical\tdavical_dba\ttrust\n" > $TMP_FOLDER/pg_hba.conf.addition cat $TMP_FOLDER/pg_hba.conf.addition $TMP_FOLDER/pg_hba.conf.old > $(cat $TMP_FOLDER/find_result) echo "The pg_hba.conf at "$(cat $TMP_FOLDER/find_result)" has been updated to accept connection from localhost for the davical databse. Reloading postgresql config now (only works with postgres 8.3)." /etc/init.d/postgresql-8.3 reload if [ ! $? -eq 0 ]; then echo "\nWARNING: Postgresql configuration could not be reloaded automaticly. You will have to run \" su postgres -c /usr/share/davical/dba/create-database.sh\" manually after this script" else echo "Running the script to create the database." su postgres -c /usr/share/davical/dba/create-database.sh if [ ! $? -eq 0 ]; then echo "An error occured when installing the database. FAILED." fi fi fi fi fi

if [ -f "/etc/apache2/sites-available/$VHOST_FILE_NAME" ]; then echo "Virtual host file already existing. Overwrite? [y/n]" read ok else read="y" fi

if [ $ok != "y" -a $ok != "Y" ]; then echo "Skipping." else if [ -f "$(dirname $0)/$VHOST_FILE_NAME" ]; then cp $(dirname $0)/$VHOST_FILE_NAME /etc/apache2/sites-available/. a2ensite $VHOST_FILE_NAME echo "Virtual host installed" grep "SSLEngine on" "$(dirname $0)/$VHOST_FILE_NAME" if [ $? -eq 0 ]; then echo "Enabling ssl in apache as it seems to be enabled in your virtual host file." if [ -e $SSL_DIR ]; then echo "SSL directory already eyisting. No certificates created." else mkdir $SSL_DIR cd $SSL_DIR

openssl req -new > $SSL_PREFIX.cert.csr openssl rsa -in privkey.pem -out $SSL_PREFIX.cert.key openssl x509 -in $SSL_PREFIX.cert.csr -out $SSL_PREFIX.cert.crt -req -signkey $SSL_PREFIX.cert.key -days 1460 fi a2enmod ssl fi /etc/init.d/apache2 reload else echo "No virtual host file named $VHOST_FILE_NAME found. Skipping the virtual host installation. FAILED." fi fi

if [ -f "/etc/davical/config.php" ]; then echo "Php config file already existing. Overwrite? [y/n]" read ok else read="y" fi

if [ $ok != "y" -a $ok != "Y" ]; then echo "Skipping." else cat <<-'EOF'> /etc/davical/config.php domain_name = "calendar.example.net"; // $c->sysabbr     = 'DAViCal'; // $c->admin_email = 'admin@example.net'; // $c->system_name = "Example DAViCal Server"; // $c->enable_row_linking = true;
 * 1) always use trailing tabs for the here document lines

$c->pg_connect[] = 'dbname=davical port=5432 user=davical_app'; ?>	EOF echo "Php config installed at /etc/davical/config.php." fi

echo "Done."

exit 0

A basic virtual host file
You will have to edit some information according to your setup.

 DocumentRoot /usr/share/davical/htdocs DirectoryIndex index.php index.html ServerName davical.example.net ServerAlias calendar.example.net Alias /images/ /usr/share/davical/htdocs/images/  AllowOverride None Order allow,deny Allow from all  AcceptPathInfo On php_value include_path /usr/share/awl/inc php_value magic_quotes_gpc 0 php_value register_globals 0 php_value error_reporting 2 php_value default_charset "utf-8" php_admin_flag suhosin.server.strip off php_value magic_quotes_runtime 0 
 * 1) Virtual Host def for Debian packaged DAViCal

Note: When using PHP via CGI/FastCGI, "AcceptPathInfo Default" is enough.