#!/bin/sh
#--------------------------------------------------------------------
# Config for tbbsV1.3.xx
# configuration program for tbbs
# WARNIG : This program is alpha !
#
# If you have any problems or bugs with this program, 
# please let me know.
#
# This script needs dialog 0.4
# 
# (c) 1995   <runge@nina.boerde.de>
#



DIALOG=dialog

#Dialog-Switch-File
DLCK=/tmp/tbbs.setup/dialog



#Your favorite editor
#EDITOR="joe " 
EDITOR=`cat ../etc/config/EDITOR`

#Your 'Multimedia-Editor'
WENDY=`cat ../etc/config/M.EDITOR`

LESS=`cat ../etc/config/LESS`



# tempory file
TEMP=/tmp/tbbs.setup/config.answers

# config file
CONFIG_BACK=/tmp/config.backup


CONFIG=/tmp/tbbs.config



do_main() {

   $DIALOG --title "ATTENTION: YOUR ARE SURE, NO USER IS ONLINE!" --yesno \
      "Are you sure?\n\nThis script create self different configuration. \nWhen Users are online, the script can run incorectly!" 9 70
    if [ ! $? = 0 ]; then
     clear;
     kill -9 0;
    fi
exit ;  


}




#
# define_bool sets the value of a boolean argument
#
#	define_bool define value
#
function define_bool () {
        case "$2" in
         "y" | "Y")
		echo "$1=y" >>$CONFIG
		echo "#define $1 1" >>$CONFIG_H
		;;

         "m" | "M")
		echo "$1=m" >>$CONFIG
		echo "#undef  $1" >>$CONFIG_H
		;;

         "n" | "N")
		echo "# $1 is not set" >>$CONFIG
		echo "#undef  $1" >>$CONFIG_H
                ;;
	esac
	eval "$1=$2"
}


#
# readln reads a line into $ans.
#
#       readln prompt default
#
function readln () {
        if [ "$DEFAULT" = "-d" ]; then
                echo "$1"
                ans=$2
        else
                echo -n "$1"
                IFS='@' read ans </dev/tty || exit 1
                [ -z "$ans" ] && ans=$2
        fi
}






function bool () {
        ans=""
        def="y"
        case "$def" in
         "y") defprompt="Y/n"
              ;;
         "n") defprompt="N/y"
              ;;
        esac
        while [ "$ans" != "y" -a "$ans" != "n" ]; do
                readln "$1 [$defprompt] " "$def"
        done
        case $ans in
         "y" | "Y")
#		echo "$1=y" >>$CONFIG
		echo "done...."
		exit
		;;

         "n" | "N")
		clear;
     		kill -9 0;
                ;;
	esac
}



do_main_sh() {

 clear
 echo "ATTENTION: YOUR ARE SURE, NO USER IS ONLINE!" 
 bool
 exit ;  
}




# +++++ main() ++++++
if test -f $DLCK; then do_main; \
else \
  do_main_sh; \
fi
