0 #!/bin/sh

#for anyone reading this: first why? second this is the installer of forumspace 

#color def
export BLACK='\033[30m'
export RED='\033[31m'
export GREEN='\033[32m'
export YELLOW='\033[33m'
export BLUE='\033[34m'
export MAGENTA='\033[35m'
export CYAN='\033[36m'
export WHITE='\033[37m'

export BRIGHT_BLACK='\033[90m'
export BRIGHT_RED='\033[91m'
export BRIGHT_GREEN='\033[92m'
export BRIGHT_YELLOW='\033[93m'
export BRIGHT_BLUE='\033[94m'
export BRIGHT_MAGENTA='\033[95m'
export BRIGHT_CYAN='\033[96m'
export BRIGHT_WHITE='\033[97m'

export BG_BLACK='\033[40m'
export BG_RED='\033[41m'
export BG_GREEN='\033[42m'
export BG_YELLOW='\033[43m'
export BG_BLUE='\033[44m'
export BG_MAGENTA='\033[45m'
export BG_CYAN='\033[46m'
export BG_WHITE='\033[47m'

export BOLD='\033[1m'
export DIM='\033[2m'
export UNDERLINE='\033[4m'
export BLINK='\033[5m'
export INVERT='\033[7m'
export RESET="\033[0m"
. /var/gopher-forum-db/config.txt


clear
printf "Welcome on the installer of the gopher server for forumspace!\n"
if [ -z "$(id | grep -n root)" ]; then
    printf "[$RED Error $BRIGHT_WHITE]: The script must be ran in sudo / root mode!\n"
    exit 0
fi

printf "welcome on the configuration center of forumspace, here are the current information:\n\nPublic ip address: $pubip\nPublic port: $pubport\nPublic ssh port: $pubsshport\nConfigured os: $osconfig\nconfigured email: $emailconfig\n\nto configure forumspace please type \"C\" else type \"Q\""
while true; do
    read -p "Enter ethier \"C\" or to quit type \"Q\"> " config_input
    if [ -z "$install_input" ]; then 
        echo "$YELLOW Warning:$BRIGHT_WHITE The input was empty please make sure to input something!"
    elif [ "$install_input" = "I" ]; then
        printf "STEP [1/4]: domain configuration\nDetected public ip adress: $pubip\nis this correct? if not please enter the domain name (example.com) or ip you wish to use if this is correct please press enter"
        read -p "choice? > " config_input
        if [ -n "$config_input" ]; then
            export pubip="$config_input"
        fi 
        printf "STEP [2/4]: port configuration\nCurrent port usage for gopher: $pubport\nis this correct? if not please enter the port you wish to use, if it is correct please simply press enter"
        read -p "choice? > " config_input
        if [ -n "$config_input" ]; then
            export gopher_port="$config_input"
        fi 
        printf "STEP [3/4]: port configuration\nCurrent port usage for ssh: $pubsshport\nis this correct? if not please enter the port you wish to use, if it is correct please simply press enter"
        read -p "choice? > " config_input
        if [ -n "$config_input" ]; then
            export ssh_port="$config_input"
        fi 
        printf "STEP [4/4]: port configuration\nPlease enter a email that user will contact you over in case of ban apeals or issue's"
        while true; do
            read -p "choice? > " config_input
            if [ -n "$config_input" ]; then
                export email="$config_input"
                break
            else
                 printf "[$YELLOW Warning $BRIGHT_WHITE]: You must enter a email that user can contact you in case of problems "
            fi 
        done
        printf "#this config file is auto generated please do not edit it\n\npubip=\"$pubip\"\npubport=\"$gopher_port\"\nosconfig=\"$osconfig\"\nemailconfig=\"$email\"" > /var/gopher-forum-db/config.txt
        printf "\n\n$(cat /var/gopher/forum/logos/ForumSpace.logo)\nConfiguration changed successfully here are the information:\nPublic ip address: $pubip\nPublic access port: $gopher_port\nEmail for ban apeal and bug report will be sent to: $email"
    elif [ "$install_input" = "Q" ]; then
        break
    fi
done
