#!/usr/bin/env python

"""
Copyright 2014 Sam Dodrill <shadowh511@gmail.com>

This software is under GPL.
"""

from os import system

def promptUser(prompt, default):
    inp = raw_input("%s [%s]> " % (prompt, default))

    if inp == "":
        return default
    else:
        return inp

def promptYesNo(prompt, default=True):
    inp = False if promptUser(prompt, "Y") == "N" else True
    return inp

configflags = ["./configure"]

system("clear")

art = """
 _______ __                              __          __       _______ ______ ______     __
|    ___|  |.-----.--------.-----.-----.|  |_.---.-.|  |_____|_     _|   __ \      |.--|  |
|    ___|  ||  -__|        |  -__|     ||   _|  _  ||  |______||   |_|      <   ---||  _  |
|_______|__||_____|__|__|__|_____|__|__||____|___._||__|     |_______|___|__|______||_____|"""

welcome ="""
Welcome to the Elemental-IRCd Configuration script. This script will help you choose the
best compile flags for your installation of Elemental-IRCd.
"""

print(art)
print(welcome)

print("Please specify where you would like to install Elemental-IRCd.")
installloc = promptUser("Install location?", "$HOME/ircd")

print("")

print("Please specify the maximum nickname length. This must be the same across")
print("all servers in your network or you risk desyncs. The maximum is 50.")

nicklen = 100
while nicklen > 51:
    if nicklen != 100:
        print "Error: you must choose a value under 50."

    nicklen = int(promptUser("Maximum nickname length?", "31"))

print("")

print("Would you like to disable small network support? This increases the size")
print("of a few buffers in the code and can increase performance on large networks.")

smallnet = promptYesNo("Small network? (Y/N)")

configflags.append("--prefix=%s" % installloc)
configflags.append("--with-nicklen=%s" % nicklen)

if not smallnet:
    configflags.append("--enable-small-net")
else:
    configflags.append("--disable-small-net")

print("\nThat should be it for now. Running %s" % " ".join(configflags))

raw_input("Press enter to continue... ")

system(" ".join(configflags))

print(art)

print("""
Next, run make and make install. Then copy %s/etc/example.conf to
%s/etc/ircd.conf and read through the example configuration completely to make
sure your install is tailored to your needs. After that, run %s/bin/ircd
and start to connect clients and servers as you need.

If you have any problems, please check the documentation in the doc/ folder
of the source repository. If problems persist please stop by #elemental-ircd
on irc.yolo-swag.com and ask. Running Elemental-IRCd in insane conditions may
make support either very difficult or at most impossible.""" %\
    (installloc, installloc, installloc))

# vim: set ts=4 sw=4 tw=0 et