#!/bin/sh

AGENTS="imip_person.py imip_person_outgoing.py imip_resource.py"
MODULES="markup.py imip_store.py vCalendar.py vContent.py vRecurrence.py"
INSTALL_DIR=/var/lib/imip-agent
WEB_INSTALL_DIR=/var/www/imip-agent

if [ ! -e "$INSTALL_DIR" ]; then
    mkdir -p "$INSTALL_DIR"
fi

cp $AGENTS "$INSTALL_DIR"
cp $MODULES "$INSTALL_DIR"

if [ ! -e "$INSTALL_DIR/imiptools" ]; then
    mkdir "$INSTALL_DIR/imiptools"
    if [ ! -e "$INSTALL_DIR/imiptools" ]; then
        mkdir "$INSTALL_DIR/imiptools/handlers"
    fi
fi

if [ -e "$INSTALL_DIR/imiptools/config.py" ]; then
    if [ ! -e "$INSTALL_DIR/imiptools/config.py.backup" ]; then
        mv "$INSTALL_DIR/imiptools/config.py" "$INSTALL_DIR/imiptools/config.py.backup"
    fi
fi

cp imiptools/*.py "$INSTALL_DIR/imiptools/"
cp imiptools/handlers/*.py "$INSTALL_DIR/imiptools/handlers/"

if [ ! -e "$WEB_INSTALL_DIR" ]; then
    mkdir -p "$WEB_INSTALL_DIR"
fi

cp imip_manager.py "$WEB_INSTALL_DIR"
cp htdocs/styles.css "$WEB_INSTALL_DIR"

if [ ! -e "$WEB_INSTALL_DIR/imipweb" ]; then
    mkdir "$WEB_INSTALL_DIR/imipweb"
fi

cp imipweb/*.py "$WEB_INSTALL_DIR/imipweb/"
