#!/bin/sh -e

SYSCONFDIR='/etc/httpd2/conf'

if [ -z "$1" ]; then
	echo "Which site would you like to enable?"
	echo -n "Your choices are: "
	ls $SYSCONFDIR/sites-available/*.conf | \
	sed -e "s,$SYSCONFDIR/sites-available/\(.*\).conf,\1,g" | xargs echo
	echo -n "Site name? "
	read SITENAME
else
	SITENAME="$1"
fi

if [ "${SITENAME:0:7}" = "default" ]; then
	PRIORITY="000"
fi

if [ -e "$SYSCONFDIR/sites-enabled/$SITENAME.conf" -o \
     -e "$SYSCONFDIR/sites-enabled/$PRIORITY-$SITENAME.conf" ]; then
	echo "Site config $CONFNAME.confThis site is already enabled!"
	exit 0
fi

if ! [ -e "$SYSCONFDIR/sites-available/$SITENAME.conf" ]; then
	echo "Site config $CONFNAME.conf does not exist!"
	exit 1
fi

if [ "$PRIORITY" = "000" ]; then
	ln -sf ../sites-available/$SITENAME.conf \
		"$SYSCONFDIR/sites-enabled/$PRIORITY-$SITENAME.conf"
else
	ln -sf ../sites-available/$SITENAME.conf \
		"$SYSCONFDIR/sites-enabled/$SITENAME.conf"
fi

echo "Site $SITENAME installed;"
echo "	run service httpd2 condreload to fully enable."
