#!/bin/sh

###############################################
# Set Variables
###############################################

# CONFIGURATION CACHE (e.g. ../config.cache)
CACHEFILE="../../config.cache"

# REGISTRATION INFORMATION CACHE FILE (no need to alter this)
REGCACHE="register.cache"

# SENDMAIL PATH
SENDMAIL="/usr/sbin/sendmail"

# SCRIPT VERSION NUMBER (DO NOT ALTER)
REGISTERVERSION="1.3"

# DO NOT CHANGE IF YOU WANT TO REGISTER WITH ANOPE
REGISTRYADDRESS="register@anope.org"

################################################
# END OF CONFIGURATION
# YOU ARE NOT REQUIRED TO CHANGE ANYTHING BELOW
################################################

if [ $0 != "./register" ] ; then
	echo "Warning: Run this file while in the /src/bin/ directory (e.g. ./register)"
	exit 1
fi

if [ ! -f $CACHEFILE ] ; then
        echo "Warning: Configuration cache file missing. Run ./Config first"
        exit 1
fi

if [ ! -f $SENDMAIL ] ; then
	echo "Warning: Sendmail cannot be found. Please open this file and set variable correctly"
	exit 1;
fi

clear 

if [ -f $REGCACHE ] ; then
	echo "Previous registration cache file found. Removing..."
	rm $REGCACHE
fi

	echo "##################################################"
	echo "Anope registration script (v$REGISTERVERSION)"
	echo "##################################################"
	echo "This script allows you to register your network"
	echo "with the Anope central registry. This gives us"
	echo "an idea of how many networks use Anope and what options"
	echo "they compile with so we can spend more time developing"
	echo "options that are more widely used. Note: The options"
	echo "you selected in ./Config will be sent." 
	echo "You will be asked a series of questions, if you wish"
	echo "to be listed in the public network database all the"
	echo "information will be required."
	echo "NOTE: NO PRIVATE OR SENSITIVE INFORMATION WILL BE SENT"
	echo "##################################################"
	echo "Would you like to register? [Type YES to continue]"
	read answer

if [ $answer = "YES" ] || [ $answer = "yes" ] || [ $answer = "Yes" ] ; then

	echo "Beginning registration..."
	echo "1. What is your network name? (e.g. Anope IRC Network)"
	read NETWORKNAME
	echo CONNECTADDRESS=\"$NETWORKNAME\" >> $REGCACHE
	echo "2. What is your network's connection address (e.g. irc.anope.org)"
	read CONNECTADDRESS
	echo CONNECTADDRESS=\"$CONNECTADDRESS\" >> $REGCACHE
	echo "3. Primary contact email address? (e.g. irc-admin@anope.org)"
	read CONTACTEMAIL
	echo CONTACTEMAIL=\"$CONTACTEMAIL\" >> $REGCACHE
	echo "4. What is your network's website address (e.g. http://www.anope.org)"
	read WEBSITEADDRESS
	echo WEBSITEADDRESS=\"$WEBSITEADDRESS\" >> $REGCACHE
	echo "5. Would you like your network to be listed in a public database?"
	echo "[Please type YES if you would like to be listed]"
	read LISTED 
	echo LISTED=\"$LISTED\" >> $REGCACHE
	echo "6. (Bonus Devel-Only Question) Why did the chicken cross the road?!" 
	read BONUS
	echo BONUS=\"$BONUS\" >> $REGCACHE
	echo >> $REGCACHE
	echo "Processing registration..."
	cat $CACHEFILE >> $REGCACHE
	$SENDMAIL $REGISTRYADDRESS < $REGCACHE 
		if [ -f $REGCACHE ] ; then
		echo "Cleaning up..."
		rm $REGCACHE
		fi
	echo "Registration Completed. Thank you for registering Anope."
	exit 0;

fi

echo "Registration Cancelled"
