def DefSettings(stuff):
	"""fucntion interacts with the user and defines all settings based on the dictionary we built"""
	for key,value in sorted(stuff.items(), key=lambda e: e[1][3]):##sort the dictionary OF lists based on 3rd entry
		gui.reset_scrn(stuff)
		gui.cur_pos(1,27,stuff[key][0],"4;32;40")## print out info ##
		if stuff[key][1] is 0: ## this is a user input feild
			stuff = settings.set_option(key,raw_input(key+"[\x1b[1;31;40m"+stuff[key][2]+"\x1b[0m]: "),stuff[key][2],stuff)## get input from user and place back into our settings
		else: ## this is just information so give the user some time to read it 
			gui.cur_pos(1,27,stuff[key][0]+": \x1b[1;31;40m"+stuff[key][2],"1;32;40")## GREEN with RED option
			raw_input("Press Enter to continue installation....")
def DefSettings(stuff):
    """fucntion interacts with the user and defines all settings based on the dictionary we built"""
    for key, value in sorted(stuff.items(), key=lambda e: e[1][
            3]):  ##sort the dictionary OF lists based on 3rd entry
        gui.reset_scrn(stuff)
        gui.cur_pos(1, 27, stuff[key][0], "4;32;40")  ## print out info ##
        if stuff[key][1] is 0:  ## this is a user input feild
            stuff = settings.set_option(
                key,
                raw_input(key + "[\x1b[1;31;40m" + stuff[key][2] +
                          "\x1b[0m]: "), stuff[key][2],
                stuff)  ## get input from user and place back into our settings
        else:  ## this is just information so give the user some time to read it
            gui.cur_pos(1, 27,
                        stuff[key][0] + ": \x1b[1;31;40m" + stuff[key][2],
                        "1;32;40")  ## GREEN with RED option
            raw_input("Press Enter to continue installation....")
def main():
	## TODO rebuild Q + A section with a loop to dynamicly load values from the settings dictionary ##
	## dynamic Q + A section finished DefSettings(STUFF)
	gui.reset_scrn(INSTALLER_SETTINGS)
	gui.cur_pos(1,27,"Welcome to the MaNGOS installer.\nDurring this script we will figure out how you want your MaNGOS server set up","0;0;0")
	raw_input("Press Enter to initilize installer....")
	
	## BUILD OPTIONS WITH USER INPUT ##
	DefSettings(INSTALLER_SETTINGS) ## Interact with user to define MaNGOS Environment Settings ##

	## BUILD PATH ##
	gui.cur_pos(1,27,"Elivating Permissions to clean out old directory and install new user (this is completly safe as we are only erasing the mangos home folder)","0;0;0")
	subprocess.call(shlex.split('sudo rm -Rf '+settings.SERV_HOME))
	subprocess.call(shlex.split('sudo rm -Rf '+INSTALLER_SETTINGS["INSTALL_DIR"][2])) ## We end up recompiling the server and reconfiguring it during an install ##
	subprocess.call(shlex.split('sudo groupadd --system '+INSTALLER_SETTINGS["MANGOS_SYS_GROUP"][2])) ## it is ideal to run bolth services on there own group
	subprocess.call(shlex.split('sudo groupadd --system '+INSTALLER_SETTINGS["REALMD_SYS_GROUP"][2])) ## this is to stick with the *IX standard way of things
	subprocess.call(shlex.split('sudo mkdir -p '+settings.CODE_BASE))
	subprocess.call(shlex.split('sudo mkdir -p '+INSTALLER_SETTINGS["INSTALL_DIR"][2])) ## build the install directory and get it ready to go
	subprocess.call(shlex.split('sudo chown -R '+env.UserName()+':'+INSTALLER_SETTINGS["MANGOS_SYS_GROUP"][2]+' '+settings.CODE_BASE)) ## set perms for user to clone ##
	subprocess.call(shlex.split('sudo mkdir -p '+INSTALLER_SETTINGS["GIT_REPO_CI_WEB"][2])) ## we need to add the web directory before configurin it
	subprocess.call(shlex.split('sudo chown -R '+env.UserName()+':'+INSTALLER_SETTINGS["MANGOS_SYS_GROUP"][2]+' '+INSTALLER_SETTINGS["GIT_REPO_CI_WEB"][2])) ## change owner of the web directory ready for installing the webpage
	## Initilize Repository ##
	gui.reset_scrn(INSTALLER_SETTINGS)
	gui.cur_pos(1,28,"CLONING REPOSITORY TO "+INSTALLER_SETTINGS["GIT_REPO_CI_SERVER"][2],"1;31;40")
	git_server_handle = Repo.clone_from("https://github.com/CollectiveIndustries/server.git",INSTALLER_SETTINGS["GIT_REPO_CI_SERVER"][2])
	#reset_scrn()
	gui.cur_pos(1,29,"CLONING REPOSITORY TO "+INSTALLER_SETTINGS["GIT_REPO_CI_DBS"][2],"1;31;40")
	git_database_handle = Repo.clone_from("https://github.com/CollectiveIndustries/Mangos_world_database.git",INSTALLER_SETTINGS["GIT_REPO_CI_DBS"][2])
	#reset_scrn()
	gui.cur_pos(1,30,"CLONING REPOSITORY TO "+INSTALLER_SETTINGS["GIT_REPO_CI_SD2"][2],"1;31;40")
	git_scriptdev2_handle = Repo.clone_from("https://github.com/CollectiveIndustries/scriptdev2-cata.git",INSTALLER_SETTINGS["GIT_REPO_CI_SD2"][2])
	#reset_scrn()
	gui.cur_pos(1,32,"CLONING REPOSITORY TO "+INSTALLER_SETTINGS["GIT_REPO_CI_TOOLS"][2],"1;31;40")
	git_tools_handle = Repo.clone_from("https://github.com/CollectiveIndustries/tools",INSTALLER_SETTINGS["GIT_REPO_CI_TOOLS"][2])
	
	## check and see if we are making a dry run on the compile ##
	if COMPILE_ONLY == False:
		#reset_scrn()
		gui.cur_pos(1,31,"CLONING REPOSITORY TO "+INSTALLER_SETTINGS["GIT_REPO_CI_WEB"][2],"1;31;40")
		git_web_handle = Repo.clone_from("https://github.com/CollectiveIndustries/mangos-enhanced.git",INSTALLER_SETTINGS["GIT_REPO_CI_WEB"][2])
		#reset_scrn()
		gui.cur_pos(1,32,"CLONING REPOSITORY TO "+settings.INSTALL_DIR+INSTALLER_SETTINGS["MANGOS_DATA_DIR"][2],"1;31;40")
		git_tools_handle = Repo.clone_from("https://github.com/CollectiveIndustries/Maps-VMaps-DBC.git",settings.INSTALL_DIR+INSTALLER_SETTINGS["MANGOS_DATA_DIR"][2])

	## change owner of directories ##
	gui.cur_pos(1,32,"Changing directory permissions on: "+settings.CODE_BASE,"1;31;40")
	subprocess.call(shlex.split('sudo chown -R '+env.UserName()+':'+INSTALLER_SETTINGS["MANGOS_SYS_GROUP"][2]+' '+settings.CODE_BASE))## set the owner of the directory so we can leave ROOT

	## start the MySQL Install ##
	gui.reset_scrn(INSTALLER_SETTINGS)
	_realm_db_ = MySQLdb.connect(host=INSTALLER_SETTINGS["REALM_DB_HOST"][2],
				     user=INSTALLER_SETTINGS["MYSQL_REALMD_ADMIN_USR"][2],
				     passwd=INSTALLER_SETTINGS["MYSQL_REALMD_ADMIN_PASS"][2])## pull the connection settings out and pass to the MySQL Connection
	_realm_db_cur_ = _realm_db_.cursor() ## set up our cursor so we can comunicate with the database
	_realm_db_cur_.execute("CREATE USER "+INSTALLER_SETTINGS["MYSQL_REALMD_USR"][2]+"@"+INSTALLER_SETTINGS["REALM_DB_HOST"][2]+" IDENTIFIED BY \'"+INSTALLER_SETTINGS["MYSQL_REALMD_PASS"][2]+"\';")## NO TRAILING ';'
def main():
    ## TODO rebuild Q + A section with a loop to dynamicly load values from the settings dictionary ##
    ## dynamic Q + A section finished DefSettings(STUFF)
    gui.reset_scrn(INSTALLER_SETTINGS)
    gui.cur_pos(
        1, 27,
        "Welcome to the MaNGOS installer.\nDurring this script we will figure out how you want your MaNGOS server set up",
        "0;0;0")
    raw_input("Press Enter to initilize installer....")

    ## BUILD OPTIONS WITH USER INPUT ##
    DefSettings(
        INSTALLER_SETTINGS
    )  ## Interact with user to define MaNGOS Environment Settings ##

    ## BUILD PATH ##
    gui.cur_pos(
        1, 27,
        "Elivating Permissions to clean out old directory and install new user (this is completly safe as we are only erasing the mangos home folder)",
        "0;0;0")
    subprocess.call(shlex.split('sudo rm -Rf ' + settings.SERV_HOME))
    subprocess.call(
        shlex.split('sudo rm -Rf ' + INSTALLER_SETTINGS["INSTALL_DIR"][2])
    )  ## We end up recompiling the server and reconfiguring it during an install ##
    subprocess.call(
        shlex.split('sudo groupadd --system ' +
                    INSTALLER_SETTINGS["MANGOS_SYS_GROUP"][2])
    )  ## it is ideal to run bolth services on there own group
    subprocess.call(
        shlex.split('sudo groupadd --system ' +
                    INSTALLER_SETTINGS["REALMD_SYS_GROUP"][2])
    )  ## this is to stick with the *IX standard way of things
    subprocess.call(shlex.split('sudo mkdir -p ' + settings.CODE_BASE))
    subprocess.call(
        shlex.split('sudo mkdir -p ' + INSTALLER_SETTINGS["INSTALL_DIR"][2])
    )  ## build the install directory and get it ready to go
    subprocess.call(
        shlex.split('sudo chown -R ' + env.UserName() + ':' +
                    INSTALLER_SETTINGS["MANGOS_SYS_GROUP"][2] + ' ' +
                    settings.CODE_BASE))  ## set perms for user to clone ##
    subprocess.call(
        shlex.split('sudo mkdir -p ' +
                    INSTALLER_SETTINGS["GIT_REPO_CI_WEB"][2])
    )  ## we need to add the web directory before configurin it
    subprocess.call(
        shlex.split('sudo chown -R ' + env.UserName() + ':' +
                    INSTALLER_SETTINGS["MANGOS_SYS_GROUP"][2] + ' ' +
                    INSTALLER_SETTINGS["GIT_REPO_CI_WEB"][2])
    )  ## change owner of the web directory ready for installing the webpage
    ## Initilize Repository ##
    gui.reset_scrn(INSTALLER_SETTINGS)
    gui.cur_pos(
        1, 28,
        "CLONING REPOSITORY TO " + INSTALLER_SETTINGS["GIT_REPO_CI_SERVER"][2],
        "1;31;40")
    git_server_handle = Repo.clone_from(
        "https://github.com/CollectiveIndustries/server.git",
        INSTALLER_SETTINGS["GIT_REPO_CI_SERVER"][2])
    #reset_scrn()
    gui.cur_pos(
        1, 29,
        "CLONING REPOSITORY TO " + INSTALLER_SETTINGS["GIT_REPO_CI_DBS"][2],
        "1;31;40")
    git_database_handle = Repo.clone_from(
        "https://github.com/CollectiveIndustries/Mangos_world_database.git",
        INSTALLER_SETTINGS["GIT_REPO_CI_DBS"][2])
    #reset_scrn()
    gui.cur_pos(
        1, 30,
        "CLONING REPOSITORY TO " + INSTALLER_SETTINGS["GIT_REPO_CI_SD2"][2],
        "1;31;40")
    git_scriptdev2_handle = Repo.clone_from(
        "https://github.com/CollectiveIndustries/scriptdev2-cata.git",
        INSTALLER_SETTINGS["GIT_REPO_CI_SD2"][2])
    #reset_scrn()
    gui.cur_pos(
        1, 32,
        "CLONING REPOSITORY TO " + INSTALLER_SETTINGS["GIT_REPO_CI_TOOLS"][2],
        "1;31;40")
    git_tools_handle = Repo.clone_from(
        "https://github.com/CollectiveIndustries/tools",
        INSTALLER_SETTINGS["GIT_REPO_CI_TOOLS"][2])

    ## check and see if we are making a dry run on the compile ##
    if COMPILE_ONLY == False:
        #reset_scrn()
        gui.cur_pos(
            1, 31, "CLONING REPOSITORY TO " +
            INSTALLER_SETTINGS["GIT_REPO_CI_WEB"][2], "1;31;40")
        git_web_handle = Repo.clone_from(
            "https://github.com/CollectiveIndustries/mangos-enhanced.git",
            INSTALLER_SETTINGS["GIT_REPO_CI_WEB"][2])
        #reset_scrn()
        gui.cur_pos(
            1, 32, "CLONING REPOSITORY TO " + settings.INSTALL_DIR +
            INSTALLER_SETTINGS["MANGOS_DATA_DIR"][2], "1;31;40")
        git_tools_handle = Repo.clone_from(
            "https://github.com/CollectiveIndustries/Maps-VMaps-DBC.git",
            settings.INSTALL_DIR + INSTALLER_SETTINGS["MANGOS_DATA_DIR"][2])

    ## change owner of directories ##
    gui.cur_pos(1, 32,
                "Changing directory permissions on: " + settings.CODE_BASE,
                "1;31;40")
    subprocess.call(
        shlex.split('sudo chown -R ' + env.UserName() + ':' +
                    INSTALLER_SETTINGS["MANGOS_SYS_GROUP"][2] + ' ' +
                    settings.CODE_BASE)
    )  ## set the owner of the directory so we can leave ROOT

    ## start the MySQL Install ##
    gui.reset_scrn(INSTALLER_SETTINGS)
    _realm_db_ = MySQLdb.connect(
        host=INSTALLER_SETTINGS["REALM_DB_HOST"][2],
        user=INSTALLER_SETTINGS["MYSQL_REALMD_ADMIN_USR"][2],
        passwd=INSTALLER_SETTINGS["MYSQL_REALMD_ADMIN_PASS"][2]
    )  ## pull the connection settings out and pass to the MySQL Connection
    _realm_db_cur_ = _realm_db_.cursor(
    )  ## set up our cursor so we can comunicate with the database
    _realm_db_cur_.execute(
        "CREATE USER " + INSTALLER_SETTINGS["MYSQL_REALMD_USR"][2] + "@" +
        INSTALLER_SETTINGS["REALM_DB_HOST"][2] + " IDENTIFIED BY \'" +
        INSTALLER_SETTINGS["MYSQL_REALMD_PASS"][2] + "\';")  ## NO TRAILING ';'