#!/bin/sh
#
modem() {
cat <<EOF
#!/bin/sh
#
# /etc/rc.d/rc.serial   `date '+%a %b %e %Y' 2>/dev/null`
#
# This rc.serial is started from: /etc/rc.d/rc.S
#
# This rc.serial file is created when you run: comset
#
# /dev/ttyS0 = com1 ttyS1 = com2 ttyS2 = com3 ttyS3 = com4
#
# Try to autoconfigure modem device using setserial.

# If setserial is not there abort the configuration.
[ -x /sbin/setserial ] || exit 0

echo "Configuring modem serial port: /dev/$MODEM"

/sbin/setserial -v /dev/$MODEM auto_irq skip_test autoconfig session_lockout

# There have been multiple reports of late that the auto configuration
# of the serial ports is broken with some new motherboards, especially
# multi-processor ones.  For this reason, you have the option of telling
# setserial what irq, port, your modem is on.
# Note that we still need an automatic test to find out what uart we are 
# using.

# Tell setserial what irq, port, the modem in on if it can't detect your 
# modem automatically.
# Put # above for /sbin/setserial and remove # below for your modem device.

#/sbin/setserial -v /dev/ttyS0 irq 4 port 0x3F8 skip_test autoconfig session_lockout
#/sbin/setserial -v /dev/ttyS1 irq 3 port 0x2F8 skip_test autoconfig session_lockout
#/sbin/setserial -v /dev/ttyS2 irq 4 port 0x3E8 skip_test autoconfig session_lockout
#/sbin/setserial -v /dev/ttyS3 irq 3 port 0x2E8 skip_test autoconfig session_lockout

# End...
EOF
}

if [ ! "$UID" = "0" ]; then
echo
echo "[$LOGNAME] You need to run this script as root."
echo "Try one of these to run it as root: # sudo comset"
echo "                                    # su -c comset"
echo
exit 1
fi

if ! type -all dialog >/dev/null 2>&1 ; then
echo "Can't find 'dialog', i can't run without 'dialog' on your system."
exit 
fi

SCD() {
dialog --backtitle "Vector Linux ...at the speed of light." --title "SELECT CALLOUT DEVICE" \
--menu "Please select the callout device which you would like\n\
to use for your modem:" 20 60 10 \
"ttyS0" "COM1: under DOS" \
"ttyS1" "COM2: under DOS" \
"ttyS2" "COM3: under DOS" \
"ttyS3" "COM4: under DOS" \
"ttyS4" "COM5: under DOS" \
"ttyS5" "COM6: under DOS" \
"ttyS6" "COM7: under DOS" \
"ttyS7" "COM8: under DOS" \
"ttyS15" "PCTEL Modem"    \
"ttySHCF0" "HSF/HCF Modem"  \
"cuaHCF0"  "HSF/HCF Modem" 2> /tmp/callout

 if [ $? = 1 ]; then
  rm -f /tmp/callout
 else
  MODEM="`cat /tmp/callout`"
  rm -f /tmp/callout
  (cd /dev && ln -sf $MODEM modem)

modem > /etc/rc.d/rc.serial
chmod 755 /etc/rc.d/rc.serial
 fi
}

dialog --backtitle "Vector Linux ...at the speed of light." --title "MODEM CONFIGURATION" --yesno \
"Comset will create a symbolic link /dev/modem that will point   
to the actual modem device (ttyS0, ttyS1, ttyS2, ttyS3).\n  
You can change this link later if you put your modem on a 
different port.\n\n\
The setserial modem configure file /etc/rc.d/rc.serial\n\
will also be created for your modem device.\n\n\
Would you like to set up your modem?" 14 68
if [ $? = 0 ]; then

if cat /proc/tty/driver/serial 2>/dev/null | grep -q "DSR" ; then
MODEM="ttyS`cat /proc/tty/driver/serial | grep "DSR" | cut -b1`"
COM=`echo $MODEM | cut -b5`
dialog --backtitle "Vector Linux ...at the speed of light." --title "Possible modem detected!" --yesno "I think you \
have a modem on device /dev/$MODEM = COM`expr $COM + 1` under DOS, 
this could be wrong! \n 
Chose <Yes> to accept or <No> to change." 8 68

if [ $? = 1 ]; then
SCD
else
(cd /dev && ln -sf $MODEM modem)
modem > /etc/rc.d/rc.serial
chmod 755 /etc/rc.d/rc.serial
fi
else
SCD
fi
fi

SMT() {
dialog --backtitle "Vector Linux ...at the speed of light." --title "SELECT MOUSE TYPE" --menu "These mouse types are supported:" 13 68 7 \
"1" "Serial mouse. Microsoft protocol (/dev/ttyS0 etc)" \
"2" "Standard PS/2 style Mouse (/dev/psaux)" \
"3" "USB mouse support (/dev/input/mice)" \
"4" "Logitech Bus Mouse (/dev/logibm)" \
"5" "ATI XL Bus Mouse (/dev/atibm)" \
"6" "Microsoft Bus Mouse (/dev/inportbm)" \
"7" "Mouse Systems serial Mouse (/dev/ttyS0 etc)" 2> /tmp/mtype
 if [ $? = 1 ]; then
  rm -f /tmp/mtype
 fi
 if [ -f /tmp/mtype ]; then
  MOUSE_TYPE="`cat /tmp/mtype`"
 else
  unset MOUSE_TYPE
  rm -f /tmp/mtype
 fi
 if [ "$MOUSE_TYPE" = "1" -o "$MOUSE_TYPE" = "6" ]; then
dialog --backtitle "Vector Linux ...at the speed of light." --title "SELECT SERIAL PORT" --menu "Your mouse requires a serial port.  Which one would\n\
you like to use?" 12 60 4 \
"ttyS0" "COM1: under DOS" \
"ttyS1" "COM2: under DOS" \
"ttyS2" "COM3: under DOS" \
"ttyS3" "COM4: under DOS" 2> /tmp/mport
  if [ $? = 1 ]; then
   rm -f /tmp/mport
  fi
  if [ -f /tmp/mport ]; then
   MOUSE_DEVICE="`cat /tmp/mport`"
  (cd /dev; ln -sf $MOUSE_DEVICE mouse)
  else
   unset MOUSE_DEVICE
   rm -f /tmp/mport
  fi
 elif [ "$MOUSE_TYPE" = "2" ]; then
  (cd /dev && ln -sf psaux mouse)
 elif [ "$MOUSE_TYPE" = "3" ]; then
  (cd /dev && ln -sf input/mice mouse)
 elif [ "$MOUSE_TYPE" = "4" ]; then
  (cd /dev && ln -sf logibm mouse)
 elif [ "$MOUSE_TYPE" = "5" ]; then
  (cd /dev && ln -sf atibm mouse)
 elif [ "$MOUSE_TYPE" = "6" ]; then
  (cd /dev && ln -sf inportbm mouse)
 fi
}

dialog --backtitle "Vector Linux ...at the speed of light." --title "MOUSE CONFIGURATION" \
--yesno "This part of the configuration process will create a\n\
link /dev/mouse pointing to the actual mouse device.\n 
You can change this later if the setting chosen does not 
work, or if you switch to a different type of mouse.\n
Would you like to set up your mouse?" 11 64
if [ $? = 0 ]; then

if dmesg 2>/dev/null | grep -i -q "detected ps/2 mouse" ; then
dialog --backtitle "Vector Linux ...at the speed of light." --title "Possible mouse detected!" --yesno "I think you \
have a PS/2 mouse on device /dev/psaux, this could be wrong! \n
Chose <Yes> to accept or <No> to change." 7 76

if [ $? = 1 ]; then
SMT
else
(cd /dev && ln -sf psaux mouse)
fi
else
SMT
fi
fi
echo



