#!/bin/bash

#
# BBS main menu - shell script 
# Example setup from The Gnu BBS - you have to configure menus for local setup
# 
# Freeware by Andreas Schiffler, 1995
#

#
# Initialization: TERM EDITOR VISUAL NEWSREADER MAILER
#
# Initial values for programs:
#
HTTP_CLIENT="lynx" 
HTTP_LINK_1=""
HTTP_LINK_2="ftp://jeeves"
#
# ----  Initial values for changable settings (customize these)
#
TERM_DEFAULT="vt100"
EDITOR_DEFAULT="joe"
VISUAL_DEFAULT="less"
MAILER_DEFAULT="elm"
NEWSREADER_DEFAULT="rtin"
#
# ----
#
if [ -r ~/.BBSterm ]; then
 TERM=`cat ~/.BBSterm`;
else
 TERM=$TERM_DEFAULT;
 echo $TERM >~/.BBSterm;
fi
export TERM
reset
if [ -r ~/.BBSeditor ]; then
 EDITOR=`cat ~/.BBSeditor`;
else
 EDITOR=$EDITOR_DEFAULT;
 echo $EDITOR >~/.BBSeditor;
fi
export EDITOR
reset
if [ -r ~/.BBSvisual ]; then
 VISUAL=`cat ~/.BBSvisual`;
else
 VISUAL=$VISUAL_DEFAULT;
 echo $VISUAL >~/.BBSvisual;
fi
export VISUAL
if [ -r ~/.BBSnewsreader ]; then
 NEWSREADER=`cat ~/.BBSnewsreader`;
else
 NESREADER=$NEWSREADER_DEFAULT;
 echo $NEWSREADER >~/.BBSnewsreader;
fi
if [ -r ~/.BBSmailer ]; then
 MAILER=`cat ~/.BBSmailer`;
else
 MAILER=$MAILER_DEFAULT;
 echo $MAILER >~/.BBSmailer;
fi

#
# The main menu loop
#
while [ 0 ]; do 

#
# Main menu dialog (edit this)
#
dialog \
--title     "*** The Gnu BBS ***   M-A-I-N  M-E-N-U   *** The Magic BBS ***" \
--menu      "\
...............................................................\n\
...... 28.8KBps V.42   (306) 652-7849   Saskatoon, Sask. ......\n\
.... Sysop: Andreas Schiffler   System: Linux on 486DX4-100 ...\n\
... Use '-' and '+' keys to select and 'Enter' to continue. ...\n\
...............................................................\
" 22 70 10 \
"1st BBS"   "Enter the cyberspace of -The-Gnu-" \
"2nd BBS"   "Enter the realms of -The-Magic-" \
"E-MAIL"    "Read your personal mail and send letters" \
"NEWS"      "Read and post news articles" \
"GAMES"     "Online games for virtual enjoyment" \
"TOOLS"     "Online utility programs" \
"SETTINGS"  "Customize terminal, editor, pager, news, mail, etc." \
"PASSWORD"  "Change your password" \
" "         " " \
"LOGOUT"    "Disconnect from the BBS ..." \
2>/tmp/menuselection;
SELECTION=`cat /tmp/menuselection`;
rm /tmp/menuselection;

#
# BBS 1 
#
if [ "$SELECTION" = "1st BBS" ]; then
 ${HTTP_CLIENT} $HTTP_LINK_1
fi;

#
# BBS 2
#
if [ "$SELECTION" = "2nd BBS" ]; then
 ${HTTP_CLIENT} $HTTP_LINK_2
fi;

#
# Menuitem: Mail (call up the mailer)
#
if [ "$SELECTION" = "E-MAIL" ]; then
 ${MAILER};
fi;

#
# Menuitem: News (call up the newsreader)
#
if [ "$SELECTION" = "NEWS" ]; then
 ${NEWSREADER};
fi;

#
# Menuitem: Games 
#
if [ "$SELECTION" = "GAMES" ]; then
dialog --title "The Games Domain" \
--menu "" 10 60 2 \
"NETHACK"     "Text based D&D game" \
2>/tmp/menuselection;
SELECTION=`cat /tmp/menuselection`;
rm /tmp/menuselection;
if [ "$SELECTION" = "NETHACK" ]; then
 clear;
 echo "Not installed at the moment ...";
 sleep 1;
fi
fi;

#
# Menuitem: Tools 
#
if [ "$SELECTION" = "TOOLS" ]; then
dialog --title "The Toolbox" \
--menu "" 10 60 2 \
"CALENDAR"     "Look at the current months calendar" \
2>/tmp/menuselection;
SELECTION=`cat /tmp/menuselection`;
rm /tmp/menuselection;
if [ "$SELECTION" = "CALENDAR" ]; then
 clear
 cal
 sleep 2
fi

fi;

#
# Menuitem: Change settings
#
if [ "$SELECTION" = "SETTINGS" ]; then
dialog --title "User settings menu" \
--menu "\nThese settings are stored in various files of your home directory.\n" 16 78 5 \
"TERMINAL"   "Change your terminal emulation, [now: $TERM]" \
"EDITOR"     "Change the default editor, [now: $EDITOR]" \
"PAGER"      "Change the default pager for textdisplay, [now: $VISUAL]" \
"MAILER"     "Change the default mailer program, [now: $MAILER]" \
"NEWSREADER" "Change the default newsreader, [now: $NEWSREADER]" \
2>/tmp/menuselection;
SELECTION=`cat /tmp/menuselection`;
rm /tmp/menuselection;
#
# Menuitem: Settings - Terminal
#
if [ "$SELECTION" = "TERMINAL" ]; then
 dialog --title "Change terminal emulation, [now: $TERM]" \
 --menu "This setting has to match local setting (i.e. in terminal\n\
 program that connects." 16 70 8 \
 "vt100"      "DEC's VT 100 remote terminal emulation" \
 "vt200"      "DEC's VT 2xx remote terminal emulation" \
 "vt300"      "DEC's VT 3xx remote terminal emulation" \
 "ansi"       "ANSI remote terminal emulation" \
 "console"    "Terminal emulation for local connects" \
 2>/tmp/menuselection;
 NEWTERM=`cat /tmp/menuselection`;
 rm /tmp/menuselection;
 if [ "$NEWTERM" != "" ]; then
  TERM=$NEWTERM
  export TERM;
  echo $TERM >~/.BBSterm;
  reset;
 fi;
 fi;
#
# Menuitem: Settings - Editor
#
 if [ "$SELECTION" = "EDITOR" ]; then
  dialog --title "Change default editor, [now: $EDITOR]" \
  --menu "\nChoose with whatever you are comfortable with.\n" 15 70 4 \
 "joe"      "Simple but good editor with online help" \
 "pico"     "Even simpler editor with online help" \
 "vi"       "The standard Unix editor - use if you know it" \
 "emacs"    "The standard power-editor from the GNU project" \
 2>/tmp/menuselection;
 NEWEDITOR=`cat /tmp/menuselection`;
 rm /tmp/menuselection;
 if [ "$NEWEDITOR" != "" ]; then
  EDITOR=$NEWEDITOR;
  export EDITOR;
  echo $EDITOR >~/.BBSeditor;
 fi;
 fi;
#
# Menuitem: Settings - Pager
#
 if [ "$SELECTION" = "PAGER" ]; then
   dialog --title "Change default pager, [now: $VISUAL]" \
   --menu "\nChoose whichever you like best.\n" 11 70 2 \
  "less"     "Advanced text pager with search capability and more" \
  "more"     "Simple but standard pager" \
  2>/tmp/menuselection;
  NEWVISUAL=`cat /tmp/menuselection`;
  rm /tmp/menuselection;
  if [ "$NEWVISUAL" != "" ]; then
   VISUAL=$NEWVISUAL;
   export VISUAL;
   echo $VISUAL >~/.BBSvisual;
  fi;
 fi;
#
# Menuitem: Settings - Mailer
#
 if [ "$SELECTION" = "MAILER" ]; then
   dialog --title "Change default mailer, [now: $MAILER]" \
   --menu "\nChoose whichever you like best. The mailer will\n\
show all unread personal mail but also allow access to old\n\
mail as well as sending mail to other users.\n" 13 70 2 \
  "elm"      "Simple but good mailer with online help" \
  "pine"     "More sophisticated, menu driven mailer" \
  2>/tmp/menuselection;
  NEWMAILER=`cat /tmp/menuselection`;
  rm /tmp/menuselection;
  if [ "$NEWMAILER" != "" ]; then
   MAILER=$NEWMAILER;
   echo $MAILER >~/.BBSmailer;
  fi;
 fi;
#
# Menuitem: Settings - Newsreader
#
 if [ "$SELECTION" = "NEWSREADER" ]; then
   dialog --title "Change default newsreader, [now: $NEWSREADER]" \
   --menu "\nChoose whichever you like best. The newreader will\n\
organize the news into threads and lets you read and write\n\
articles.\n" 13 70 2 \
  "tin"      "Almost a standard, for the local newspool" \
  "rtin"     "Same as tin, for the remote newspool" \
  2>/tmp/menuselection;
  NEWNEWSREADER=`cat /tmp/menuselection`;
  rm /tmp/menuselection;
  if [ "$NEWNEWSREADER" != "" ]; then
   NEWSREADER=$NEWNEWSREADER;
   echo $NEWSREADER >~/.BBSnewsreader;
  fi;
 fi;
fi;

if [ "$SELECTION" = "PASSWORD" ]; then
 dialog --title "Password change instructions" \
 --msgbox "\
\nThe old password is prompted for an verified first.\n\n\
A new password is prompted for twice, to avoid typing mis-\n\
takes.  Unless the user is the superuser, the new password\n\
must have more than six characters, and must  have  either\n\
both  upper and lower case letters, or digits.  Some pass-\n\
words which  are  similar  to  the  user's  name  are  not\n\
allowed.\n\n\
A password consisting of all digits is allowed.\n" 16 66;
 if [ $? = 0 ]; then
  clear;
  passwd;
  sleep 1
 fi;
fi;

if [ "$SELECTION" = "LOGOUT" ]; then
 break;
fi;

done

#
# one can use a definite 'logout' here, so that people don't get
# stuck on a shell level.
#

