#!/bin/sh
if [ -r /tmp/SeTcolor -o "$COLOR" = "on" ]; then # we can use color...

 dialog --title "SET YOUR MODEM SPEED" --menu "Please select a modem speed. \
You may use setserial later to make 38400 stand for a higher baud rate if \
these speeds aren't fast enough." \
16 60 7 \
"38400" "" \
"19200" "" \
"9600" "" \
"4800" "" \
"2400" "" \
"1200" "" \
"300" "Ouch!" \
2> /tmp/SeTreturn
 if [ $? = 1 -o $? = 255 ]; then
  rm -f /tmp/SeTreturn
  exit
 fi
 BAUD="`cat /tmp/SeTreturn`"
else
 while [ 0 ]; do
  echo "SELECT DEFAULT MODEM SPEED"
  echo
  echo "Valid speeds are: 38400, 19200, 9600, 4800, 2400, 1200, 300"
  echo 
  echo "Please enter a modem speed. You may use setserial later to make "
  echo "38400 stand for a higher baud rate if these speeds aren't fast "
  echo "enough."
  echo
  echo -n "Enter speed ==> "
  read BAUD
  if [  "$BAUD" = "38400" -o "$BAUD" = "19200" -o "$BAUD" = "9600" \
-o "$BAUD" = "4800" -o "$BAUD" = "2400" -o "$BAUD" = "1200" \
-o "300" ]; then
   break;
  fi
  echo 
  echo "Invalid choice. Try again."
  echo
 done
fi
mkdir -p var/lib/minicom
cat << EOF > var/lib/minicom/minirc.dfl
pr port             /dev/modem
pu baudrate         $BAUD
pu bits             8
pu parity           N
pu mdialpre         ATDT
pu updir            .
pu downdir          .
pu scriptdir        /var/lib/minicom
pu backspace        DEL
EOF
chmod 644 var/lib/minicom/minirc.dfl
mkdir -p etc/skel
cat << EOF > etc/skel/.kermrc
set line /dev/modem
set speed $BAUD
set modem hayes
set file type bin
set file name lit
set rec pack 1000
set send pack 1000
set window 5
set prompt Linux Kermit> 
EOF
cat << EOF > etc/skel/.term/termrc
#From johnsonm@stolaf.edu Sun Dec 13 05:07:38 1992
#The format of the ~/.term/termrc file.
#All blank lines, and line begining with a '#' are ignored.
#All command words must be in lowercase.
#valid lines are... 

compress off
# To turn of compression. Useful for compressing modems
# No benchmarks have been done to see which does better compression,
# modems, or term. See OPTIONS to compression compression on/off on
# a per client basis.

#escape 158
# tells term never to transmit character with decimal number
# 158. Use the ouput of checkline to find out what to put
# here. Valid number are anything between 32 and 255
# Use one line for each character.
# ranges are valid. I.e. "escape 128-159"

escape 0-31
escape 128-159
# the above are some handy escapes that will cause most lines to work.
# but they are very inefficent (they escape 25% of all bytes sent!!!)
# so try and escape as few as possible.


baudrate $BAUD
# Sets the baudrate. Actually used to limit the maximum
# number of characters sent per second.
# valid numbers are anything >= 2400. Default is zero.

#shift 224
# Sets a 'shift' value. This number is XOR'ed with
# all bytes before they are sent.  This is in a bid to
# reduce the number of escaped characters sent. Histograms
# show that 224-255 has the least number of characters sent
# and 0-31 has the most. This should improve things. The
# default is zero for backward compatability.

#flowcontrol 500
# Tell term to generate control-Q's everynow and then
# used in case your terminal server understands flow control
# and things will accidently turn it off. i.e. line noise
# sends a control-S.

window 3
# Set the maximum number of packets that can be outstanding
# useful values are around 2-6.

timeout 100
# sets the length of time to wait before retransmitting a 
# packet. If useing a large window size, then increase this
# value. A smaller window sizes merits a smaller timeout 
# value. If getting too many re-transmits, then increase.
# measured in 1/20th's of a second. 

#force on
# Turn transmit forceing on.

noise on
# Turn on printing out line noise.

#sevenbit
# If were are running on a 7 bit line..

#seven_in
# If your incoming line is seven bit.
# Note that these are symetric. If you have seven_in on one end, you MUST
# have seven_out on the other.

#seven_out
# If your outgoing line is seven bit. "seven_in" and "seven_out" together
# are the same as "sevenbit".


ignore 17
# Silently strip the character 17 from the input stream.

ignore 19
# ditto.

# breakout 24
# set the breakout character to be control-X. So five control-X's types
# to term will cause it to exit.

# chdir /usr/users/oreillym
# Make the default directory usr/users/oreillym (my home dir).
# 
EOF
chmod 755 etc/skel/.term/termrc
for DIR in root home/gonzo home/pit home/hell ; do
 if [ -d $DIR ]; then
  if [ ! -d $DIR/.term ]; then
   mkdir $DIR/.term
  fi
  cp etc/skel/.kermrc $DIR/.kermrc
  cp etc/skel/.less $DIR/.less
  cp etc/skel/.term/termrc $DIR/.term/termrc 
 fi
done
if [ -d home/gonzo ]; then
 chown --recursive gonzo.users home/gonzo 2> /dev/null
fi
if [ -d home/pit ]; then
 chown --recursive snake.users home/pit 2> /dev/null
fi
if [ -d home/hell ]; then
 chown --recursive satan.users home/hell 2> /dev/null
fi
