#!/bin/sh -e

SYSCONFDIR='/etc/httpd2/conf'

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

if [ -e "$SYSCONFDIR/extra-enabled/$CONFNAME.conf" -o \
     -e "$SYSCONFDIR/extra-enabled/$PRIORITY-$CONFNAME.conf" ]; then
	echo "Extra config $CONFNAME.conf is already enabled!"
	exit 0
fi

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

ln -sf ../extra-available/$CONFNAME.conf \
	"$SYSCONFDIR/extra-enabled/$CONFNAME.conf"

echo "Extra config $CONFNAME installed;"
echo "	run service httpd2 condreload to fully enable."
