#!/bin/sh

# Configures the Darkbot

echo
echo "-------------------------------------------"
echo "Don't worry if you misconfigure because you"
echo "can always do it later from:"
echo
echo "/usr/local/etc/darkbot/configure"
echo "-------------------------------------------"
echo
while [ -z "$EEDITOR" ]
do
	echo -n "Enter the name of the text editor you would like to use [pico]: "
	read EEDITOR
	if [ -z "$EEDITOR" ]; then
		echo "No editor specified, defaulting to pico."
		EEDITOR=pico
fi
done
echo
echo "You will need to build the setup.ini for Darkbot..."
echo 
echo "Hit ENTER to continue."
read x
echo
while [ -z "$NICK" ]
do
	echo -n "Enter the nickname you would like to use for your bot: "
	read NICK
	if [ -z "$NICK" ]; then
		echo "Enter a nickname for your bot!"
		sleep 1
		echo
fi
done
while [ -z "$USERID" ]
do
	echo -n "Enter the userid you would like to use [`whoami`]: "
	read USERID
	if [ -z "$USERID" ]; then
		echo "No userid specified... defaulting to `whoami`"
		USERID=`whoami`
	fi
done
while [ -z "$CHAN" ]
do
	echo -n "Enter the channel $NICK should join: "
	read CHAN
	if [ -z "$CHAN" ]; then
		echo "You must enter a channel!"
		sleep 1
		echo
	fi
done
while [ -z "$REALNAME" ]
do
	echo -n "Enter the realname info for $NICK [default]: "
	read REALNAME
	if [ -z "$REALNAME" ]; then
		echo "Using default realname.."
		REALNAME="Download me from http://darkbot.net"
	fi
done
while [ -z "$CMDCHAR" ]
do
	echo -n "Enter the command character $NICK should respond to [!]: "
	read CMDCHAR
	if [ -z "$CMDCHAR" ]; then
		echo "No CMDCHAR specified, defaulting to !"
		CMDCHAR=!
	fi
done
while [ -z "$VHOST" ]
do
        echo -n "Enter the VHOST you want to use. If none, hit enter [0]:"
        read VHOST
        if [ -z "$VHOST" ]; then
                echo "None entered. Will not use VHOST."
                VHOST=0
        fi
done
echo 
echo "Writing data settings to setup.ini ....."
echo "NICK=$NICK" > dat/setup.ini
echo "USERID=$USERID" >> dat/setup.ini
echo "CHAN=$CHAN" >> dat/setup.ini
echo "REALNAME=$REALNAME" >> dat/setup.ini
echo "CMDCHAR=$CMDCHAR" >> dat/setup.ini
echo "VHOST=$VHOST" >> dat/setup.ini
echo "AUTOTOPIC=0" >> dat/setup.ini
echo 
echo "Next you need to specify the server $NICK should connect to."
echo 
while [ -z "$SERVER" ]
do
	echo
	echo -n "Enter the server your bot should connect to [irc.superchat.org]: "
	read SERVER
	if [ -z "$SERVER" ]; then
		echo "No server specified. defaulting to irc.superchat.org"
		SERVER=irc.superchat.org
	fi
done
while [ -z "$PORT" ]
do
	echo -n "Enter the port to connect to on $SERVER [6667]: "
	read PORT
	if [ -z "$PORT" ]; then
		echo "No port specified, defaulting to 6667"
		PORT=6667
	fi
done
echo "$SERVER $PORT (Added: `date`)" > dat/servers.ini
echo
./Adduser
