#!/bin/sh -e

if ! grep -q "^www-data:" /etc/passwd;
then
    echo -n "The www-data user is missing!  Attempt to fix? "
    read X
    if [ "$X" = "Y" -o "$X" = "y" ];
    then
	echo "Here goes nothing ... "
	/usr/sbin/update-passwd
    fi
fi

if ! grep -q "^www-data:" /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 ... "
	/usr/sbin/update-passwd
    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
