#!/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 = "default" ]; then
	PRIORITY="000"
fi

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

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

if [ $SITENAME = "default" ]; 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."
