#! /bin/sh
# preinst script for apache
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>

case "$1" in
    install|upgrade)

    if ! grep -q "^www" /etc/group;
    then
	echo -n "The www-data group is missing!  Attempt to fix? "
	read X
	if [ "$X" = "Y" -o "$X" = "y" ];
	then
	    echo "Here goes nothing ... "
            addgroup --gid 33 --force-badname www-data
            echo
	fi
    fi

    if ! grep -q "^www" /etc/passwd;
    then
	echo -n "The www-data user is missing!  Attempt to fix? "
	read X
	if [ "$X" = "Y" -o "$X" = "y" ];
	then
            adduser --system --home /var/www --no-create-home \
            --uid 33 --gid 33 --disabled-password --force-badname www-data
            echo
	fi
    fi

    # See which version was installed.

    if [ "$1" = install -o "$1" = upgrade ] && [ "$2" != "" ]
    then
	if [ ! -d /etc/apache -a -d /etc/httpd ]
	then
	    echo Copying existing configuration from "\`/etc/httpd'" to "\`/etc/apache'..."
	    mkdir -m 755 /etc/apache &&
		(cd /etc/httpd; tar cf - .) | (cd /etc/apache; tar xpf -)
	fi
    fi

    ;;

    abort-upgrade)
    ;;

    *)
        echo "preinst called with unknown argument \`$1'" >&2
        exit 0
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


