#!/bin/bash

#This program was written by Tim Peeler <thp@linuxforce.net> for
#the Debian system (but may be used by others). Permission is
#granted to copy, distribute and/or modify this document under
#the terms of the GPL, Version 2 or any later version.  

GB_SRC=/usr/share/achims-guestbook
LN_S="index.html admin gif guestbook.php input.php language.php location_eng.php output.php preview.php search.php smileyfilegenerator.php smileys.php tools.php"
CP_A="*.inc config.php data temp"
WWWWRITABLE="config.php data temp"
HTACCESS="data temp"

case "$1" in
    "--help"|"-h")
        cat <<EOF
Usage: install-achims-guestbook [install directory]

This script is used to install Achims guestbook into a directory specified
in your website.  This will copy modifiable conf files, look and feel
include files and create links to the installed guestbook scripts.  Once
you have an installation, maintainance is as simple as upgrading the debian
package.
EOF
        exit 0;
    ;;
    "--version"|"-v")
        echo "install-achims-guestbook version 0.2";
        exit 0;
    ;;
    *)
        DEST_DIR=$1
    ;;
esac

if [ ! -d $DEST_DIR ] ; then
  mkdir $DEST_DIR
fi

for file in $LN_S ; do
    ln -s $GB_SRC/$file $DEST_DIR;
done

for file in $CP_A ; do
    cp -a $GB_SRC/$file $DEST_DIR;
done

cd $DEST_DIR
for dir in $WWWWRITABLE ; do
  chmod g+w $dir
  chgrp www-data $dir
done

for dir in $HTACCESS ; do
  cat <<EOF >$dir/.htaccess
Order Deny,Allow
Deny from all
EOF
done

cat <<EOF

Done copying and linking files.  Your admin password is "admin".  It is
suggested that you change the password as soon as possible.  Don't forget
to add your guestbook to /etc/achims-guestbook/config-locations.php

The default site layout has been installed, if you would prefer a
different look and feel you can copy one of the two layouts provided in
/usr/share/achims-guestbook/layout to your guestbook directory.  You may
also want to try out one of the various color schemes by copying one
of the other cascading style sheets to guestbook.css in your guestbook
directory.

EOF
