#!/bin/sh
# -----------------------------------------------------------------------------
#	configuration script for SCRDRV
# -----------------------------------------------------------------------------
#
#	Copyright (C) 1995 by Todd Fries [tfries@umr.edu]
#
# -----------------------------------------------------------------------------
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 2, or (at your option)
#	any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; see the file COPYING.  If not, write to
#	the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#
# ----------------------------------------------------------------------------

mainmenu () {
 dialog --title "Linux GGI" --menu "\nWelcome\
 to Linux GGI Setup.\n\
 Which option would you like?" 22 74 11 \
"HELP"    "Read the GGI README.CONFIG HELP file" \
"MONITOR" "Choose monitor info [now: $monitor_class $monitor_type]" \
"CHIP"    "Choose chip info    [now: $chip_class $chip_type]" \
"CLOCK"   "Choose clock info   [now: $clock_class $clock_type]" \
"RAMDAC"  "Choose ramdac info  [now: $dac_class $dac_type]" \
"KERNEL"  "Choose kernel       [now: $kern_class $kern_type]" \
"EXIT"    "Exit Linux GGI Configuration" 2> /tmp/ggiset
}

if [ -f .config ]; then
  monitor_class=`cat .config | grep MON_CLASS | cut -d'=' -f2`
  monitor_type=`cat .config | grep MON_TYPE | cut -d'=' -f2`
  chip_class=`cat .config | grep CHIP_CLASS | cut -d'=' -f2`
  chip_type=`cat .config | grep CHIP_TYPE | cut -d'=' -f2`
  clock_class=`cat .config | grep CLK_CLASS | cut -d'=' -f2`
  clock_type=`cat .config | grep CLK_TYPE | cut -d'=' -f2`
  dac_class=`cat .config | grep DAC_CLASS | cut -d'=' -f2`
  dac_type=`cat .config | grep DAC_TYPE | cut -d'=' -f2` 
  kern_class=`cat .config | grep KERN_CLASS | cut -d'=' -f2`
  kern_type=`cat .config | grep KERN_TYPE | cut -d'=' -f2` 
fi

while [ true ] ;
do
 mainmenu
 MAINSELECT=`cat /tmp/ggiset`
 # Start checking what to do. Some modules may reset MAINSELECT to run the
 # next item in line.

 if [ "$MAINSELECT" = "" ]; then
   rm -f /tmp/ggiset
   clear
   exit 1
 fi
 
 if [ "$MAINSELECT" = "HELP" ]; then
   dialog --textbox README.CONFIG 24 76
 fi

 if [ "$MAINSELECT" = "EXIT" ]; then
   if [ "$monitor_class" = "" ]; then clear; exit 1; fi
   if [ "$monitor_type"  = "" ]; then clear; exit 1; fi
   if [ "$chip_class"    = "" ]; then clear; exit 1; fi
   if [ "$chip_type"     = "" ]; then clear; exit 1; fi
   if [ "$clock_class"   = "" ]; then clear; exit 1; fi
   if [ "$clock_type"    = "" ]; then clear; exit 1; fi
   if [ "$dac_class"     = "" ]; then clear; exit 1; fi
   if [ "$dac_type"      = "" ]; then clear; exit 1; fi
   if [ "$kern_class"    = "" ]; then clear; exit 1; fi
   if [ "$kern_type"     = "" ]; then clear; exit 1; fi
   dialog --infobox "Saving configuration..." 5 50
   mv -f .config .config.old 2>/dev/null
   cat << EOF > .config
#
# .config file generated by configure
#

# monitor driver and class
MON_CLASS=$monitor_class
MON_TYPE=$monitor_type

# chipset driver
CHIP_CLASS=$chip_class
CHIP_TYPE=$chip_type

# clock chip driver
CLK_CLASS=$clock_class
CLK_TYPE=$clock_type

#ramdac driver
DAC_CLASS=$dac_class
DAC_TYPE=$dac_type

#kernel driver
KERN_CLASS=$kern_class
KERN_TYPE=$kern_type

#version
EOF
   cat ../.version >>.config
   rm -f /tmp/ggiset
   sleep 1
   clear
   exit
 fi

 if [ "$MAINSELECT" = "MONITOR" ]; then
     monitor/.configure $monitor_class $monitor_type
     monitor_class=`cat /tmp/.monclass`
     monitor_type=`cat /tmp/.montype`
     rm -f /tmp/.monclass /tmp/.montype
#     MAINSELECT=CHIP
 fi

 if [ "$MAINSELECT" = "CHIP" ]; then
     chipset/.configure $chip_class $chip_type
     chip_class=`cat /tmp/.chipclass`
     chip_type=`cat /tmp/.chiptype`
     rm -f /tmp/.chipclass /tmp/.chiptype
#     MAINSELECT=CLOCK
 fi

 if [ "$MAINSELECT" = "CLOCK" ]; then
     clock/.configure $clock_class $clock_type
     clock_class=`cat /tmp/.clockclass`
     clock_type=`cat /tmp/.clocktype`
     rm -f /tmp/.clockclass /tmp/.clocktype
#     MAINSELECT=RAMDAC
 fi

 if [ "$MAINSELECT" = "RAMDAC" ]; then
     ramdac/.configure $dac_class $dac_type
     dac_class=`cat /tmp/.dacclass`
     dac_type=`cat /tmp/.dactype`
     rm -f /tmp/.dacclass /tmp/.dactype
#     MAINSELECT=KERNEL
 fi

 if [ "$MAINSELECT" = "KERNEL" ]; then
     kernel/.configure $kern_class $kern_type
     kern_class=`cat /tmp/.kernclass`
     kern_type=`cat /tmp/.kerntype`
     rm -f /tmp/.kernclass /tmp/.kerntype
 fi

done
