#!/bin/sh

set -e

EXAMPLES=/usr/share/doc/cvs-conf/examples

get_config() {
    db_get cvs-conf/cvs_create
    cvs_create="$RET"
    db_get cvs-conf/cvs_root
    cvs_root="$RET"
    db_get cvs-conf/cvs_rsh
    cvs_rsh="$RET"
    db_get cvs-conf/cvs_module
    cvs_module="$RET"
}

case "$1" in
    configure)
	. /usr/share/debconf/confmodule
        get_config
	if [ "$cvs_create" = "true" ]; then
		cd ${EXAMPLES}/config
#		CVSROOT=${cvs_root}; export CVSROOT
#		unset CVS_RSH
#		[ "${cvs_rsh}" = "(none)" ] || CVS_RSH=${cvs_rsh}
#		export CVS_RSH
#		echo "CVSROOT=$CVSROOT"
#		echo "CVS_RSH=$CVS_RSH"
		echo "${cvs_root}" | grep '^:pserver:' >/dev/null && \
		    cvs -d ${cvs_root} login
		cvs -d ${cvs_root} import -m "" ${cvs_module} cvs-conf start
	fi
	exit 0
	;;
    upgrade|abort-upgrade|abort-remove|abort-deconfigure)
	exit 0
        ;;
    *)
         echo "postinst called with unknown argument \`$1'" >&2
         exit 0
    ;;
esac

#DEBHELPER#
