#!/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 and / or only bash
# 
# (c) 1995 All rights reserved. 	 <runge@nina.boerde.de>          
#---------------------------------------------------------------------
#
#
# Redistribution and use of this script, with or without modification, is 
# permitted provided that the following conditions are met:
#
#  Redistributions of this script must retain the above copyright
#  notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# 
#

SH_VERSION="sh0.8"
PATH="$PATH:/sbin:/usr/sbin:/usr/bin:/bin:."
CHECKIT=/tmp/tbbs.checkit.log

COPYW="(c)1996 runge@boerde.de"


HHOME=`pwd`


DIALOG=dialog

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

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

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

#Your favorite Pager 
LESS=`cat ../etc/config/LESS`

echo "Warning: This script needs dialog 0.4, wait...." 
#sleep 0
echo "check ROOT GID/UID, wait....."

echo "script-failure at this point?  "
echo "   check symb.link:  lrwxrwxrwx   root root   [ -> test"

if [ ! $UID = 0 ]
then
 echo
 echo "Sorry, you must being root (UID|GID == 0)";
 echo
 exit;
fi 
clear; 
# tempory file
TEMP=/tmp/tbbs.setup/config.answers

# config file
CONFIG_BACK=/tmp/tbbs.setup/config.backup


CONFIG=/tmp/tbbs.setup/debug.config


if ! test -f ../src/Makefile; then clear; echo "deperties are missing -> STOP"; \
echo "You must first \"make dep\" and \"make install\" !"; \
exit; \
fi


if ! test -f ../bin/bbs; then clear; echo "binarys missing -> STOP"; \
echo "You must first run \"make most\"!"; \
exit; \
fi

ver=`cut -c21-26 ../src/version.h`
version=`echo $ver`

ziptest=`test -f uzip`

organisation=../etc/config/organisation

system=../etc/config/system

CHECKTEST=./etc/spool/.checksetup 

smarthost=../etc/config/smarthost

uucpsite=../etc/config/uucpsite

uucpbang=../etc/config/uucpbang

domain1=../etc/config/domain1

domain2=../etc/config/domain2

refelct=../etc/config/reflect

uupath=../etc/config/uupath

location=../etc/config/location

phone=../etc/config/phone

HOME=../etc/config/HOME
BIN=../etc/config/BIN



#tools
function readln () {
    echo
    echo -n "$PROMPT [$PROMPT2] > "
    IFS='@' read ans </dev/tty || exit 1
    [ -z "$ans" ] && ans=$2
}










#make default settings
do_default() 
{
./do_question;

echo "make defaults automaticly...."
cd ..

if test -f etc/spool/.home.is.hard.coded; then echo "Warning: BBS-HOME is hard-coded!"; \
echo ""; \
fi

if ! test -f etc/spool/.home.is.hard.coded; then  \
echo "`pwd`">etc/config/HOME ;\
echo "`pwd`/bin">etc/config/BIN ; \
rm -f /etc/tbbs.setup ; \
ln -sf "`pwd`/etc/config" /etc/tbbs.setup ; \
fi

echo "make bbs-mail-default" ; 
rm -f /usr/bin/xmd 
ln -sf "`pwd`/bin/xmd" /usr/bin/xmd
rm -f /usr/bin/bbs.who
ln -sf "`pwd`/bin/bbs.who" /usr/bin/bbs.who

rm -f /usr/bin/bbs.shell
ln -sf "`pwd`/bin/bbs.shell" /usr/bin/bbs.shell

sleep 2

if ! test -f etc/config/nntp.server
then
 echo "set nntp-server to localhost:";
 echo "`hostname -f`">etc/config/nntp.server
fi 

do_chat_default;
#		echo "All Checkit-Output is write to $CHECKIT"   
#		echo "-> Don't press Ctrl+C! <-";echo; sleep 2; 
#		sleep 0; tail -f $CHECKIT &
#		bin/bbs.checkit +c >$CHECKIT;
#		bin/bbs.update +p >>$CHECKIT;

if ! test -f $CHECKTEST ; then echo 'welcome on tbbs, first i check the bbs-system-setup....' ;\
		bin/bbs.checkit +c ; \
		bin/bbs.update +p ; \
		sleep 3 ;\
		echo "`pwd`/etc/spool/.checksetup">`pwd`/etc/spool/.checksetup
		echo ;\
		else \
		echo "checkup... ignore"; \
		echo; fi

cd Config
}


do_mailsize() {

if test -f $DLCK; then \
$DIALOG --inputbox "during what mailsize (in bytes) will been log" \
  9 60 2> /tmp/tbbs.setup/size ; \
 else \
  clear ;\
  echo "during what mailsize (in bytes) will been log ?" ;\
  ans="50"
  PROMPT="size ?"
  PROMPT2="bytes"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/size
fi
    if [ ! $? = 0 ]; then
      do_mail
    fi 
mv /tmp/tbbs.setup/size ../etc/config/mailsize
do_mail;
}







do_chat_default() 
{
echo "make chat - defaults ..."


echo "`pwd`/etc/chat/files/login_screen">etc/config/chat.login_sceen
echo "`pwd`/etc/chat/files/intro_screen">etc/config/chat.intro_sceen
echo "`pwd`/etc/chat/files/help">etc/config/chat.help
echo "`pwd`/etc/chat/files/power">etc/config/chat.power
echo "`pwd`/etc/chat/files/admin">etc/config/chat.admin
echo "`pwd`/etc/chat/files/sysop">etc/config/chat.op_power

}







# ---------------- do_systemdef() -------------------------------------
do_systemdef() {
echo "wait....."

if test -f $DLCK; then \
$DIALOG --title "tbbs: system-adjustments" \
   --menu "\n\
\n\
please select \n" 20 75 9 \
  1 "Organisation     : `cat $organisation`" \
  2 "System-Name      : `cat $system`" \
  3 "UUCP/SMTP-Site   : paths, smarthost, domain etc.                 " \
  4 "LOCATION         : `cat $location`"\
  5 "BBS-Phone        : `cat $phone`"\
  d "return to main                                                   " \
2> $TEMP ;\
else \
	clear; \
	echo "tbbs: system-adjustments"; \
	echo "============================================================================="; \
 echo; \
  echo "(1)  Organisation     : `cat $organisation`" 
  echo "(2)  System-Name      : `cat $system`" 
  echo "(3)  UUCP/SMTP-Site   : paths, smarthost, domain etc.                 " 
  echo "(4)  LOCATION         : `cat $location`"
  echo "(5)  BBS-Phone        : `cat $phone`"
  echo "(d)  return to main                                                   " 
 ans="d"
 PROMPT="please select"
 PROMPT2="1,2,3,4,5,d"
 readln
 echo "select-code: "
 echo $ans
 echo $ans >$TEMP
fi


#cat $TEMP
#sleep 5

    if [ ! $? = 0 ]; then
     main_menue
    fi


choice=`cat $TEMP`
case $choice in
   1) do_organisation;;
   2) do_system;;
   3) do_uucp;;
   4) do_location;;
   5) do_phone;;
   d) main_menue;  # return
    exit;
esac
}  





# ---------------- do_option() -------------------------------------
do_option() {
echo "wait....."

if test -f $DLCK; then \
$DIALOG --title "tbbs: setup-adjustments" \
   --menu "\n\
\nwarning: when you change this entrys, you must restart the \n\
main-setup-sript!\n\n\
please select your favorite tools ;-)   : \n" 20 75 9 \
  1 "ASCII-Editor              : `cat ../etc/config/EDITOR` " \
  2 "Multimedia-Editor         : `cat ../etc/config/M.EDITOR` " \
  3 "Pager                     : `cat ../etc/config/LESS` " \
  "0" "-----------------------------------------------------" \
  d "return to main            :                     " \
2> $TEMP; \
else \
  clear; \
  echo "tbbs: setup-adjustments"; \
  echo "(select favorite tools; for setup only)  "
  echo "============================================================================="; \
  echo; \
  echo "(1)   ASCII-Editor              : `cat ../etc/config/EDITOR` "; \
  echo "(2)   Multimedia-Editor         : `cat ../etc/config/M.EDITOR` "; \
  echo "(3)   Pager                     : `cat ../etc/config/LESS` "; \
  echo " -----------------------------------------------------"; \
  echo "(d)  return to main            :                     "; \
 ans="d" ; \
 PROMPT="please select" ; \
 PROMPT2="1,2,3,,d" ; \
 readln ;\
 echo "select-code: " ; \
 echo $ans ; \
 echo $ans >$TEMP; \
fi

#cat $TEMP
#sleep 5

    if [ ! $? = 0 ]; then
     main_menue
    fi


choice=`cat $TEMP`
case $choice in
   1) do_edit;;
   2) do_medit;;
   3) do_pager;;
   d) main_menue;  # return
    exit;
esac
}  




# ---------------- do_mail() -------------------------------------
do_mail() {
while true 
do 
echo "wait....."
if test -f $DLCK; then \
$DIALOG --title "tbbs: bbsmail-handling + logging" \
   --menu "\n\
log rmail  = `cat ../etc/config/log.mail`\n\n\
please select " 20 75 9 \
  1 "edit \"welcome-mail\"  (this mail get each new-user)                " \
  2 "system-signum-file for mail+news-acticle from the bbs             " \
  3 "set \"rmail (log mailsize) = on\"                                   " \
  4 "set \"rmail (log mailsize) = off\"                                  " \
  5 "log mailsize = `cat ../etc/config/mailsize` bytes" \
  6 "edit \"invalid-user-entry\"mail (get each user with invalid entrys)" \
  d "return to main                                                   " \
2> $TEMP ;\
else \
  clear; \
  echo "tbbs: bbsmail-handling + logging"; \
  echo "============================================================================="; \
  echo " dip-switch:"; \
  echo "   log rmail  = `cat ../etc/config/log.mail`"; \
  echo "(1)  edit \"welcome-mail\"  (this mail get each new-user) "; \
  echo "(2)  system-signum-file for mail+news-acticle from the bbs"; \
  echo "(3)  set \"rmail (log mailsize) = on\" "; \
  echo "(4)  set \"rmail (log mailsize) = off\" ;"; \
  echo "(5)  log mailsize = `cat ../etc/config/mailsize` bytes"; \
  echo "(6)  edit \"invalid-user-entry\"mail (get each user with invalid entrys)" ; \
  echo "(d)  return to main            :                     "; \
 ans="d" ; \
 PROMPT="please select" ; \
 PROMPT2="1,2,3,,d" ; \
 readln ;\
 echo "select-code: " ; \
 echo $ans ; \
 echo $ans >$TEMP; \
fi


    if [ ! $? = 0 ]; then
     main_menue
    fi


choice=`cat $TEMP`
case $choice in
   1) $EDITOR ../etc/mail/welcome.user.txt;;
   2) do_signum;;
   3) echo "on" >../etc/config/log.mail;;
   4) echo "off" >../etc/config/log.mail;;
   5) do_mailsize;;
   6) $EDITOR ../etc/mail/invalid.entry.txt;;
   d) main_menue;  # return
    exit;
esac
done
}  



do_uucpsite() {

if test -f $DLCK; then \
$DIALOG --inputbox "what is the name UUCP/SMTP-host (where the bbs live)" \
  9 60 2> /tmp/tbbs.setup/uucpsite ; \
else
  clear ;\
  echo "hat is the name UUCP/SMTP-host (where the bbs live)?" ;\
  ans="nina"
  PROMPT="hostname ?"
  PROMPT2="nina"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/uucpsite
fi

    if [ ! $? = 0 ]; then
      do_uucp
    fi
mv /tmp/tbbs.setup/uucpsite $uucpsite
do_uucp;
}






do_edit() {

if test -f $DLCK; then \
$DIALOG --inputbox "what is the favorite ASCII-editor" \
  9 60 2> /tmp/tbbs.setup/EDITOR ; \
else
  clear ;\
  echo "what is the favorite ASCII-editor ?" ;\
  ans="joe"
  PROMPT="editor ?"
  PROMPT2="joe"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/EDITOR
fi

    if [ ! $? = 0 ]; then
      do_option
    fi
mv /tmp/tbbs.setup/EDITOR ../etc/config/EDITOR
do_option;
}


do_medit() {
if test -f $DLCK; then \
$DIALOG --inputbox "what is the favorite Multimedia-Editor (not ASCII!)" \
  9 60 2> /tmp/tbbs.setup/M.EDITOR ; \
else \
  clear ;\
  echo "what is the favorite Multimedia-Editor (not ASCII!)?" ;\
  ans="../bin/wendy"
  PROMPT="Multimedia-Editor ?"
  PROMPT2="../bin/wendy"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/M.EDITOR
fi

    if [ ! $? = 0 ]; then
      do_option
    fi
mv /tmp/tbbs.setup/M.EDITOR ../etc/config/M.EDITOR
do_option;
}



do_pager() {
if test -f $DLCK; then \
$DIALOG --inputbox "what is the favorite Paging-Tool (more/less ?)" \
  9 60 2> /tmp/tbbs.setup/LESS ; \
else
  clear ;\
  echo "what is the favorite Paging-Tool (more/less ?)" ;\
  ans="less"
  PROMPT="view-tool ?"
  PROMPT2="less"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/LESS
fi
    if [ ! $? = 0 ]; then
      do_option
    fi
mv /tmp/tbbs.setup/LESS ../etc/config/LESS
do_option;
}




do_domain1() {
if test -f $DLCK; then \
$DIALOG --inputbox "what is the hostname (with full domain)" \
  9 60 2> /tmp/tbbs.setup/domain ;\
else \
  clear ;\
  echo "what is the full hostname (with domain) ?" ;\
  ans="nina.boerde.de"
  PROMPT="full name (host+domain) ?"
  PROMPT2="nina.boerde.de"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/domain
fi
    if [ ! $? = 0 ]; then
      do_uucp
    fi
cp /tmp/tbbs.setup/domain $domain1
cp /tmp/tbbs.setup/domain $domain2
do_uucp;
}





do_bang() {
if test -f $DLCK; then \
$DIALOG --inputbox "what is your UUCp/SMTP-bangpath (not used!)" \
  9 60 2> /tmp/tbbs.setup/bang ; \
else
  clear ;\
  echo "what is your UUCp/SMTP-bangpath (not used!)?" ;\
  ans="wegaop!relay!nina!"
  PROMPT="bang"
  PROMPT2="wegaop!relay!nina!"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/bang
fi
    if [ ! $? = 0 ]; then
      do_uucp
    fi
mv /tmp/tbbs.setup/bang $uucpbang
do_uucp;
}






do_smarthost() {
if test -f $DLCK; then \
$DIALOG --inputbox "what is your smarthost" \
  9 60 2> /tmp/tbbs.setup/smarthost ; \
else  \
  clear ;\
  echo "what is your smarthost ?" ;\
  ans="relay.boerde.de"
  PROMPT="hostname ?"
  PROMPT2="relay.boerde.de"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/smarthost
fi
    if [ ! $? = 0 ]; then
      do_uucp
    fi
mv /tmp/tbbs.setup/smarthost $smarthost
do_uucp;
}



do_reflect() {
if test -f $DLCK; then \
$DIALOG --inputbox "what is your reflect-newsgroup (for user-test-mails ;-) ) " \
  9 60 2> /tmp/tbbs.setup/ref ; \
else \
  clear ;\
  echo "what is your reflect-newsgroup (for user-test-mails ;-) )?" ;\
  ans="boerde.test"
  PROMPT="newsgroup"
  PROMPT2="boerde.test"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/ref
fi


    if [ ! $? = 0 ]; then
      do_uucp
    fi
mv /tmp/tbbs.setup/ref $refelct
do_uucp;
}




do_intro0() {
if test -f $DLCK; then \
intro0;      #make the dir-list

    if [ ! $? = 0 ]; then
     do_info
    fi

choice=`cat $TEMP`
$WENDY `cat /tmp/tbbs.setup/config.answers`
do_info;
else \
  echo "not supported: please edit ~bbs/etc/languages/*.info/ -Paths external !!!!";
  sleep 5
fi
}




do_sysinfo() {
#select.language;      

$WENDY ../etc/languages/sysinfo/deutsch.sysinfo
do_info;
}




do_german_info() {
info.deutsch;      #make the dir-list

    if [ ! $? = 0 ]; then
     do_info
    fi

choice=`cat $TEMP`
$EDITOR `cat /tmp/tbbs.setup/config.answers`
do_info;
}


do_english_info() {
info.english;      #make the dir-list

    if [ ! $? = 0 ]; then
     do_info
    fi

choice=`cat $TEMP`
$EDITOR `cat /tmp/tbbs.setup/config.answers`
do_info;
}



do_francais_info() {
info.francais;      #make the dir-list

    if [ ! $? = 0 ]; then
     do_info
    fi

choice=`cat $TEMP`
$EDITOR `cat /tmp/tbbs.setup/config.answers`
do_info;
}

do_intro0_clear() {
intro0;      #make the dir-list

    if [ ! $? = 0 ]; then
     do_info
    fi

choice=`cat $TEMP`


   $DIALOG --title "clear intro.0-messages" --yesno \
"\nAre you sure, that the message `cat $TEMP` \nwill seen deleted\
!\n\n\
Sure?" 11 70


    if [ ! $? = 0 ]; then
      do_info
    fi
# exec clear

rm `cat /tmp/tbbs.setup/config.answers`
do_info;
}






do_intro1() {
if test -f $DLCK; then \
intro1;      #make the dir-list 

    if [ ! $? = 0 ]; then 
     do_info 
    fi 

choice=`cat $TEMP` 
$WENDY `cat /tmp/tbbs.setup/config.answers` 
do_info;  
else  \
echo "not supported: please edit ~bbs/etc/languages/*.info/ with a editor!" ; 
sleep 5 ; 
fi
}



do_intro1_clear() {
intro1;      #make the dir-list

    if [ ! $? = 0 ]; then
     do_info
    fi

choice=`cat $TEMP`


   $DIALOG --title "clear intro.1-messages" --yesno \
"\nAre you sure, that the message `cat $TEMP` \nwill seen deleted\
!\n\n\
Sure?" 11 70


    if [ ! $? = 0 ]; then
      do_info
    fi
# exec clear

rm `cat /tmp/tbbs.setup/config.answers`
do_info;
}











# ---------------- do_uucp() -------------------------------------
do_uucp() {
while true 
do 
echo "wait....."

if test -f $DLCK; then \
$DIALOG --title "tbbs: UUCP/SMTP: site+domain+paths, News-Smarthost, reflect-NG" \
   --menu "\n\
\n\
please select \n" 20 75 9 \
  1 "site-name                : `cat $uucpsite`" \
  2 "domain1                  : `cat $domain1`"\
  4 "bang-path (not used)     : `cat $uucpbang` " \
  5 "news-smarthost (not used): `cat $smarthost`" \
  6 "reflect-newsgroup        : `cat $refelct`" \
  d "return to main                     " \
2> $TEMP ; \
else
  clear; \
  echo "tbbs: UUCP/SMTP: site+domain+paths, News-Smarthost, reflect-NG"; \
  echo "======================================================================="
  echo "(1) site-name        : `cat $uucpsite` " 
  echo "(2) domain1          : `cat $domain1`"
  echo "(4) bang-path        : `cat $uucpbang` " 
  echo "(5) news-smarthost   : `cat $smarthost`" 
  echo "(6) reflect-newsgroup: `cat $refelct`" 
  echo "(d)  return                        " 
  ans="" ; \
  PROMPT="please select" ; \
  PROMPT2="1,2,4,5,6,d" ; \
  readln ;\
  echo "select-code: " ; \
  echo $ans ; \
  echo $ans >$TEMP; \
fi



    if [ ! $? = 0 ]; then
     main_menue
    fi


choice=`cat $TEMP`
case $choice in
   1) do_uucpsite;;
   2) do_domain1;;
   4) do_bang;;
   5) do_smarthost;;
   6) do_reflect;;
   d) main_menue; 
    exit;
esac


done
}  





# ---------------- do_info() -------------------------------------
do_info() {

if ! test -f $DLCK; then \
  echo "not supported: please config ~bbs/etc/langauges/... with a editor!"
  sleep 5
else \

while true 
do 
echo "wait....."
$DIALOG --title "tbbs: intro/info-base for user" \
   --menu "\n\
\n\
please select \n" 20 78 9 \
  1 "edit selected\"intro-0\"(this is view by foreach login,out of RIP/S++)" \
  2 "clear selected \"intro-0\"-messages                                " \
  3 "edit all \"intro-1\"(view,out of RIP/S++,in dependent from usr-cfg)" \
  4 "clear selected \"intro-1\" messages                                " \
  5 "edit/view the german info-base (command \"info\")                  " \
  6 "edit/view the english info-base (command \"info\")                 " \
  7 "edit/view the francais info-base (command \"info\")                " \
  8 "edit sysinfo-messages (german, english, francais)                " \
  9 "edit sysop-info (for rip-command: \"Sysop-Info\")                  " \
  a "edit \"./etc/issue-file\" (meaning similar /etc/issuefor unix)     " \
  b "edit \"./etc/guests.intro\" (it is viewing by guest-login)          " \
  c "edit \"./etc/languages/deutsch.news\" (it is view by \"NEW\" Command) " \
  d "return to main                                                   " \
2> $TEMP

#cat $TEMP
#sleep 5

    if [ ! $? = 0 ]; then
     main_menue
    fi


choice=`cat $TEMP`
case $choice in
   1) do_intro0;;
   2) do_intro0_clear;;
   3) do_intro1;;
   4) do_intro1_clear;;
   5) do_german_info;;
   6) do_english_info;;
   7) do_francais_info;;
   8) do_sysinfo;;
   9) $WENDY ../etc/sysop.txt;;
   a) $EDITOR ../etc/issue;;
   b) $EDITOR ../etc/guests.intro;;
   c) $EDITOR ../etc/languages/deutsch.news;;
   d) main_menue;  # return
    exit;
esac
done
fi
}  





# ---------------- do_global() -------------------------------------
do_global() {
while true 
do
echo "wait....."
if test -f $DLCK; then \
$DIALOG --title "tbbs: globalconfig and enviroment" \
   --menu "\n\
\n\
please select \n" 20 75 9 \
  1 "./etc/list.export (enviroment-setting for ext.appl./tools)       " \
  2 "./etc/list.editors (additional editors for bbs-users)            " \
  3 "./etc/list.terminals (additional terminals for bbs-user)         " \
  4 "./etc/list.udc (possibility to offer external program)           " \
  5 "./etc/list.packers (packers/archivers for tbbs)                  " \
  6 "./etc/list.games (external terminal-games for unix)              " \
  8 "./etc/www.sh (startup-script for WWW-Service)                    " \
  c "./etc/users.groups (bbs can manage with max.5 File-Usergroups)   " \
  e "return                                                           " \
2> $TEMP ; \
else
  clear; \
  echo "tbbs: globalconfig and enviroment" \
  echo "======================================================================="
  echo "(1) ./etc/list.export (enviroment-setting for ext.appl./tools)" 
  echo "(2) ./etc/list.editors (additional editors for bbs-users) "
  echo "(3) ./etc/list.terminals (additional terminals for bbs-user)" 
  echo "(4) /etc/list.udc (possibility to offer external program) " 
  echo "(5) ./etc/list.packers (packers/archivers for tbbs)" 
  echo "(6) ./etc/list.games (external terminal-games for unix) " 
  echo "(8) ./etc/www.sh (startup-script for WWW-Service) " 
  echo "(c) ./etc/users.groups (bbs can manage with max.5 File-Usergroups)" 
  echo "(e)  return                        " 
  ans="c" ; \
  PROMPT="please select" ; \
  PROMPT2="1..6,8,c" ; \
  readln ;\
  echo "select-code: " ; \
  echo $ans ; \
  echo $ans >$TEMP; \

fi




    if [ ! $? = 0 ]; then
     main_menue
    fi


choice=`cat $TEMP`
case $choice in
   1) $EDITOR ../etc/list.export;;
   2) $EDITOR ../etc/list.editors;;
   3) $EDITOR ../etc/list.terminals;;
   4) $EDITOR ../etc/list.udc;;
   5) $EDITOR ../etc/list.packers;;
   6) $EDITOR ../etc/list.games;;
   7) $EDITOR ../etc/list.providers;;
   8) $EDITOR ../etc/www.sh;;
   9) $EDITOR ../etc/alias.sh;;
   a) $EDITOR ../etc/rmail.sh;;
   b) $EDITOR ../etc/inews.sh;;
   c) $EDITOR ../etc/users.groups;;
   d) $EDITOR ../etc/login.shh;;
   e) main_menue; 
    exit;
esac
done 
}  





# ---------------- do_daemon() -------------------------------------
daemon_menue() {

exit
echo "wait....."
if test -f $DLCK; then \
$DIALOG --title "tbbs: daemon-menu" \
   --menu "\n\
\n\
please select \n" 20 75 9 \
  1 "!bbsd       : (bbs-daemon: run qwkd, bbs.doexire, mb-daemon etc.)" \
  2 "!uqwkd      : options for execute                                " \
  3 "bbs.doexpire: options,user-warnings and enviroment-setting       " \
  d "return to main                                                   " \
2> $TEMP ; \
else \

  clear; 
  echo "tbbs: daemon-menu" 
  echo "======================================================================="
  echo "(1) !bbsd       : (bbs-daemon: run qwkd, bbs.doexire, mb-daemon etc.)" 
  echo "(2) !uqwkd      : options for execute                                " 
  echo "(3) bbs.doexpire: options,user-warnings and enviroment-setting       " 
  echo "(d)  return                        " 
  ans="d" ; \
  PROMPT="please select" ; \
  PROMPT2="1..3,d" ; \
  readln ;\
  echo "select-code: " ; \
  echo $ans ; \
  echo $ans >$TEMP; \
fi




#cat $TEMP
#sleep 5

    if [ ! $? = 0 ]; then
     break
    fi

#    IGNORE_TAGFILES="-ignore_tagfiles"
#    continue;

choice=`cat $TEMP`
case $choice in
   1) do_global;;
   2) echo "c 2" >> $CONFIG;;
   3) do_expire;;
   4) ../bin/sysfileman;;
   5) echo "c 5" >> $CONFIG;;
   6) echo "c 6" >> $CONFIG;;
   d) main_menue;  # return
    exit;
esac
}  


# checks status of dialog
check_status() {

if [ "$?" != 0 ]
then
   clear
   echo -e "\nSetup canceled! return to main \n"
#   cp $CONFIG_BACK $CONFIG
#   exit
    main_menue
fi
}



do_debug() {

echo "## DEBUG ##" > $CONFIG

if test -f $DLCK; then \
$DIALOG  --title "DEBUG" --checklist "choose one or more options" 24 75 17 \
  1 nntp_log                                    off\
  2 nnmaster-db_log                            off\
  3 "devel-#1 debug-info_log for bbs-development "	off\
  4 "devel-#2 debug-info_log for bbs-development"	off\
  6 splus_log                                  off\
  7 g94_log                                    off\
  8 chatd-log                                  off\
  9 "debug-status-logfile (function-log)"            off\
  a "console-usr-logfile (volker's \"REDIRECT\".tty file )"    on\
  2>$TEMP 


check_status

choice=`cat $TEMP`
rm -f $CONFIG

for option in $choice
do
   case $option in
     \"1\") echo  "   nntp on" >> $CONFIG;;
     \"2\") echo  "   nndb on" >> $CONFIG;;
     \"3\") echo  "   devel1 on" >> $CONFIG;;
     \"4\") echo  "   devel2 on" >> $CONFIG;;
     \"6\") echo  "   chatd on" >> $CONFIG;;
     \"7\") echo  "   splusplus on" >> $CONFIG;;
     \"8\") echo  "   g94 on" >> $CONFIG;;
     \"9\") echo  "   leer on" >> $CONFIG;;
     \"a\") echo  "   console on" >> $CONFIG;;
esac  
done
echo "" >> $CONFIG
mv $CONFIG ../etc/config/debug
else \
  echo "not supported (install first 'dialog'-tool!)"
  sleep 5
fi
}














do_organisation() {
if test -f $DLCK; then \
$DIALOG --inputbox "what is the name of the orgarnization" \
  9 60 2> /tmp/tbbs.setup/orgranisation ; \
else
  clear; 
  echo "what is the name of the organization ? ";  
  ans="Boerde.DE, Magdeburg" 
  PROMPT="organization" 
  PROMPT2="Boerde.DE, Magdeburg" 
  readln 
  echo "select-code: " 
  echo $ans 
  echo $ans >/tmp/tbbs.setup/orgranisation; 
fi
    if [ ! $? = 0 ]; then
      do_systemdef
    fi
mv /tmp/tbbs.setup/orgranisation ../etc/config/organisation
do_systemdef;
}



do_system() {

if test -f $DLCK; then \
$DIALOG --inputbox "what is the name of the bbs-system" \
  9 60 2> /tmp/tbbs.setup/system ; \
else
  clear; 
  echo "what is the name of the bbs-system ?";  
  ans="nina.boerde.de" 
  PROMPT2="nina.boerde.de" 
  PROMPT="system-name" 
  readln 
  echo "select-code: " 
  echo $ans 
  echo $ans >/tmp/tbbs.setup/system; 
fi
    if [ ! $? = 0 ]; then    # cancel
      rm /tmp/tbbs.setup/system
      do_systemdef
    fi

mv /tmp/tbbs.setup/system ../etc/config/system
do_systemdef;

}

do_location() {

if test -f $DLCK; then \
$DIALOG --inputbox "where do you live (contry)" \
  9 60 2> /tmp/tbbs.setup/location ; \
else \
  clear; 
  echo "where do you live (contry) ?";  
  ans="Germany" 
  PROMPT="contry" 
  PROMPT2="Germany" 
  readln 
  echo "select-code: " 
  echo $ans 
  echo $ans >/tmp/tbbs.setup/location ;
fi

    if [ ! $? = 0 ]; then    # cancel
      rm /tmp/tbbs.setup/location
      do_systemdef
    fi

mv /tmp/tbbs.setup/location ../etc/config/location
do_systemdef;

}


do_phone() {


if test -f $DLCK; then \
$DIALOG --inputbox "what phone-calls the bbs have? " \
  9 60 2> /tmp/tbbs.setup/phone ; \
else \

  clear; 
  echo "what phone-calls the bbs have?";  
  ans="0391-0815" 
  PROMPT="bbs-phone" 
  PROMPT2="0391-0815" 
  readln 
  echo "select-code: " 
  echo $ans 
  echo $ans >/tmp/tbbs.setup/phone ;

fi

    if [ ! $? = 0 ]; then    # cancel
      rm /tmp/tbbs.setup/phone
      do_systemdef
    fi

mv /tmp/tbbs.setup/phone ../etc/config/phone
do_systemdef;

}




do_check_zip()
{
if test -f /usr/bin/zip
then
 echo "zip ok";
 exit;
fi 
 echo "zip not found";
exit;
}




# ---------------- main() -------------------------------------
main_menue() {
echo "wait....."

while true 
do
cd $HHOME

if test -f $DLCK; then \
$DIALOG --title "SETUP for tbbs 1.3$version$SH_VERSION       $COPYW" \
   --menu "\n\
At this time the tbbs-setup-script is expermiental!\n\
     " 22 71 15 \
  2 "bbs-system  : bbs-name, sysop-name, organization, etc.        " \
  7 "News-Access : nntp-server1+2; news-mode.....                  " \
  8 "Multiuser   : user-expire-daemon                              " \
  a "bbs-mail    : bbs-mail-handling, edit alias-base+welcome-mail " \
  c "Checkit     : bbs-check (system,install,permission....)       " \
  d "debug-mode  : this part is normally not select               " \
  e "setup-option: for setup-script (editor, etc....... )         " \
  f "-----------------------------------------------------------  " \
  g "Quit        : return to shell                                " \
2> $TEMP; \
else  \
	clear; \
	echo "============================================================================="; \
	echo "       (B)ulletin (B)oard (S)ystem for Linux & NetBSD"
	echo "   SETUP for tbbs 1.3$version$SH_VERSION       $COPYW"; \
	echo "============================================================================="; \
 echo; \
 	echo "  warning: expermiental-support!!!" ;\
echo "  ";  \
 echo " 2)  bbs-system  : bbs-name, sysop-name, organization, etc.        "; \
 echo " 7)  News-Access : nntp-server1+2; news-mode.....                  "; \
 echo " 8)  Multiuser   : user-expire-daemon                              "; \
 echo " a)  bbs-mail    : bbs-mail-handling, edit alias-base+welcome-mail "; \
 echo " c)  Checkit     : bbs-check (system,install,permission....)       "; \
 echo " d)  !debug-mode : this part is normally not select               "; \
 echo " e)  setup-option: for setup-script (editor, etc....... )         "; \
 echo " f)  -----------------------------------------------------------  "; \
 echo " g)  Quit        : exit setup ;)                               "; \
 ans="g"
 PROMPT="please select"
 PROMPT2="2,7,8,a,b,c,d,e,f"
 readln
 echo "select-code: "
 echo $ans
 echo $ans >$TEMP
fi


#  9 "daemons     : configure bbsd,user-expire, bbsmail, etc.      " \
#  3 "!levels     : levels / level-defaults etc.                    " \
#  4 "!filearea   : ADM-Fileman - paths,mirror-server etc.          " \
#  5 "!qwk        : paths, etc.                                     " \
#  6 "!rip1.54    : enhanced options                                " \

    if [ ! $? = 0 ]; then
     clear
     echo "Cleaning up   "
     rm -fr /tmp/tbbs.setup;
     echo "                    -> Cancel :)"
     echo "bye..."
     exit
    fi


choice=`cat $TEMP`
case $choice in
   0) exit;;
#   1) do_global;;
   2) do_systemdef;;
#  3) do_restrinktion;;
   4) do_filebase;;
   5) do_noimpl;;
   6) do_noimpl;;
   7) ./do_news;;
   8) do_user;;
   9) daemon_menue;;
   a) do_mail;;
#  b) do_info;;
   c) do_checkit;;
   d) do_debug;;
   e) do_option;;
   f) echo "wait";;
   g) clear;
       rm -fr /tmp/tbbs.setup;
      echo "bye."
      exit;
esac
done
}  

rm -fr /tmp/tbbs.setup;
mkdir /tmp/tbbs.setup;
rm -f $DLOCK
# Make sure we're really running bash.
#
# I would really have preferred to write this script in a language with
# better string handling, but alas, bash is the only scripting language
# that I can be reasonable sure everybody has on their linux machine.
#
[ -z "$BASH" ] && { echo "Configure requires bash, please install first!" 1>&2; exit 1; }
# Disable filename globbing once and for all.
# Enable function cacheing.
set -f -h


echo "check for dialog-tool.....";
if test -f /usr/bin/$DIALOG ;  then touch $DLCK; echo " -> found: /usr/bin/dialog"; fi
if test -f /usr/local/bin/$DIALOG ;  then  touch $DLCK; echo " -> found: /usr/local/bin/dialog"; fi
if test -f /sbin/$DIALOG ;  then touch $DLCK; echo " -> found: /sbin/dialog"; fi
if test -f /bin/$DIALOG ;  then  touch $DLCK; echo " -> found: /bin/dialog"; fi

#rm $DLCK; echo "!!!!!!! ALWAYS!!!! -> EXPERIMENTAL-SUPPORT!!!!!!"
if ! test -f $DLCK; then  echo " -> warning: dialog-tools not installed, use experimental SH-config-support!"; \
echo "      wait....."; sleep 0; fi

do_default;

while true
do 
  main_menue
done
rm -rf /tmp/tbbs.setup
