#!/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>
#

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

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

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


DIALOG=dialog

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


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

# config file
CONFIG_BACK=/tmp/config.backup


CONFIG=/tmp/tbbs.config



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




do_nntp_server()
{
if test -f $DLCK; then \
$DIALOG --inputbox "what is your main-nntp-host (newshost.domain.de)" \
  9 60 2> /tmp/tbbs.setup/nntp.host ; 
else \
  clear ;
  echo "what is your main-nntp-host (newshost.domain.de) ?" ;
  ans="nina.boerde.de"
  PROMPT="newshost-#1 ?"
  PROMPT2="nina.boerde.de"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/nntp.host
fi
    if [ ! $? = 0 ]; then
      exit ;
    fi
mv /tmp/tbbs.setup/nntp.host ../etc/config/nntp.server ;
do_news_server;

}


do_nntp_server2()
{
if test -f $DLCK; then \
$DIALOG --inputbox "what is your secondary-nntp-host (newshost2.domain.de)" \
  9 60 2> /tmp/tbbs.setup/nntp.host2; \
else \
  clear ;\
  echo "what is your seconydary-nntp-host (newshost2.domain.de) ?" ;\
  ans="news.cs.uni-magdenurg.de"
  PROMPT="newshost-#2 ?"
  PROMPT2="news.cs.uni-magdenurg.de"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/nntp.host2
fi
    if [ ! $? = 0 ]; then
      exit ;
    fi
mv /tmp/tbbs.setup/nntp.host2 ../etc/config/nntp.server2
do_news_server;

}




do_nntp_port()
{

if test -f $DLCK; then \
$DIALOG --inputbox "what is your nntp-service (default:nntp)\nattention: see in \
 /etc/services for more info!" \
  9 60 2> /tmp/tbbs.setup/nntp.port  ; \
else \
  clear ;\
  echo "what is nntp-service (default:nntp) ?"
  echo "  -> see in /etc/services for more info!" ;\
  ans="nntp"
  PROMPT="nntp-service"
  PROMPT2="nntp"
  readln
  echo "answer is: "
  echo $ans
  echo $ans > /tmp/tbbs.setup/nntp.port
fi

    if [ ! $? = 0 ]; then
      do_news_server;
    fi
mv /tmp/tbbs.setup/nntp.port ../etc/config/nntp.port
do_news_server;

}


do_nntp_post()
{

$DIALOG --title "nntp-posting options " \
   --menu \
"\n" 22 74 9 \
  1 "posting via nntp-server " \
  2 "posting with inews      " \
  a "Quit                                                             " \
2> $TEMP


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

choice=`cat $TEMP`
case $choice in
   1) echo "nntp-server">../etc/config/nntp.posting;;
   2) echo "inews">../etc/config/nntp.posting;;
   a) clear;
      echo "return to main..."
      do_news_server;
esac

do_news_server;
}







do_nntp_active()
{


if test -f $DLCK; then \
$DIALOG --title "read nntp-active file only by expire-date " \
   --menu \
"\n" 22 74 9 \
  1 "only by expire (fast) " \
  2 "always                " \
  a "Quit                  " \
2> $TEMP ; 

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

choice=`cat $TEMP`
case $choice in
   1) echo "by expire-date">../etc/config/nntp.active;;
   2) echo "always">../etc/config/nntp.active;;
   a) clear;
      echo "return to main..."
      do_news_server;
esac

else \
  clear; \
fi


do_news_server;
}


do_news_server() {
while true
do


if test -f $DLCK; then \
$DIALOG --title "nntp-server and options " \
   --menu \
"--------- current selections --------------\n\
nntp-server      : `cat ../etc/config/nntp.server` \n\
nntp-server2     : `cat ../etc/config/nntp.server2` \n\
nntp-service     : `cat ../etc/config/nntp.port` \n\
nntp-posting to  : `cat ../etc/config/nntp.posting` \n\
active only local: `cat ../etc/config/nntp.active.local` \n\
read nntp-active : `cat ../etc/config/nntp.active` \n" 22 74 9 \
  1 "change nntp-server  (localhost ??)                                " \
  2 "change alternative nntp-server  (news.cs.uni-magdeburg.de ??)    " \
  3 "select nntp-service (nntp ?? (nnrp....) )                        " \
  5 "read nntp-active-file by expire-date (fast-mode-option) / always " \
  0 "-----------------------------------------------------------------" \
  a "Quit                                                             " \
2> $TEMP ; \
else \
  clear; \
  echo "tbbs: nntp-server and options" 
  echo "======================================================================="
  echo "  --------- current selections --------------"
  echo "   nntp-server      : `cat ../etc/config/nntp.server` "
  echo "   nntp-server2     : `cat ../etc/config/nntp.server2` "
  echo "   nntp-service     : `cat ../etc/config/nntp.port` "
  echo "   nntp-posting to  : `cat ../etc/config/nntp.posting` "
  echo "   active only local: `cat ../etc/config/nntp.active.local` "
  echo "   read nntp-active : `cat ../etc/config/nntp.active` "
  echo " (1) change nntp-server  (localhost ??)                  " 
  echo " (2) change alternative nntp-server  (news.cs.uni-magdeburg.de ??)" 
  echo " (3) select nntp-service (nntp ?? (nnrp....) )         " 
  echo " (5) read nntp-active-file by expire-date (fast-mode-option) / always " 
  echo " (a) Quit " 
  ans="c" ; 
  PROMPT="please select" ; 
  PROMPT2="1..3,5,a" ; 
  readln ;
  echo "select-code: " ;  \
  echo $ans ; 
  echo $ans >$TEMP; 

fi


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

choice=`cat $TEMP`
case $choice in
   1) do_nntp_server;;
   2) do_nntp_server2;;
   3) do_nntp_port;;
#   4) do_nntp_post;;
   5) do_nntp_active;;
   a) clear;
      echo "return to main..."
      exit;
esac
done
}








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


$DIALOG --title "Selection: News-Access" \
   --menu \
"warning: this adjustments are bbs-global!\n\n\
---------------- news-adjustments -----------------\n\
~news/newsgroups  : `cat ../etc/config/load.newsgroups`\n\
news-access       : `cat ../etc/config/newsaccess`\
\n" 22 77 9 \
  1 "nntp.1                                           (nntp:read,write)  " \
  8 "newsgroups-options (load by default)                                " \
  a "--------------------------------------------------------------------" \
  f "Quit    -     main-menu                                             " \
2> $TEMP

#  2 "!nntp.2/nn-db (nntp: read,write; nn-database: search ) -> fast      " 
#  7 "!dbm/dbz-Support                                                    " \
#  3 "!direct/nn-db (direct: read,write; nn-database:search) ->verry fast " 
#  4 "!direct/mbd-index, (direct: read,write, mbd-index   -> slow)        " 
#  5 "!direct/mbd-newindex, (direct: read,write ->new index ->verry slow) " 
#  6 "!direct+mbd-expire(direct:read,write->new index by expire-time->slow" 



#cat $TEMP
#sleep 5

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


choice=`cat $TEMP`
case $choice in
   0) exit;;
   1) echo "nntp (1)">../etc/config/newsaccess;
      do_news_server;;
   2) echo "nntp/nn-db (2)">../etc/config/newsaccess;
      do_news_server;;
   3) echo "direct/nn-db (3)">../etc/config/newsaccess;;
   4) echo "direct/mbd-index (4)">../etc/config/newsaccess;;
   5) echo "direct/mbd-newindex (5)">../etc/config/newsaccess;;
   6) echo "direct/mbd-expire (6)">../etc/config/newsaccess;;
   7) echo "direct dbm/dbz (7)">../etc/config/newsaccess;;
   f) clear;
      echo "return to main..."
      exit ;
esac
done
}  

while true
do 
#  main
do_news_server
done
