#!/bin/sh
# $Id: drvconf,v 1.4 2000/07/22 11:28:37 marcus Exp $
#*****************************************************************************
#	configuration script for KGI chipset drivers
#*****************************************************************************
#

mainmenu () {
 dialog --title "Linux KGI" --menu "\nWelcome to Linux KGI Driver Setup.\n\
 Which option would you like?" 22 74 11 \
"HELP"    "Read the KGI README.CONFIG HELP file" \
"MONITOR" "Choose monitor driver [now: $monitor_class $monitor_type]" \
"CHIP"    "Choose chip driver    [now: $chip_class $chip_type]" \
"ACCEL"   "Choose accel driver   [now: $accel_class $accel_type]" \
"CLOCK"   "Choose clock driver   [now: $clock_class $clock_type]" \
"RAMDAC"  "Choose ramdac driver  [now: $dac_class $dac_type]" \
"VIDEO"   "Choose VideoIO driver [now: $video_class $video_type]" \
"AUTO"    "Try to autodetect the graphics card" \
"EXIT"    "Exit Linux KGI Configuration" 2> /tmp/kgiset
}

read_conf () {
  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`
    accel_class=`cat .config | grep ACCEL_CLASS | cut -d'=' -f2`
    accel_type=`cat .config | grep ACCEL_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` 
    video_class=`cat .config | grep VIDEO_CLASS | cut -d'=' -f2`
    video_type=`cat .config | grep VIDEO_TYPE | cut -d'=' -f2`
  fi
}

write_conf () {
   cat << EOF > $1
#
# .config file generated by drvconf
#

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

# chipset driver
CHIP_CLASS=$chip_class
CHIP_TYPE=$chip_type

# accel driver
ACCEL_CLASS=$accel_class
ACCEL_TYPE=$accel_type

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

# ramdac driver
DAC_CLASS=$dac_class
DAC_TYPE=$dac_type

# accel driver
VIDEO_CLASS=$video_class
VIDEO_TYPE=$video_type

# version
EOF
   cat ../.version >> $1
}

# ----------------------------------------------------------------------------
# Script starts here
# ----------------------------------------------------------------------------

read_conf

if [ ! -x `which dialog` ]; then 
    echo Sorry. We require the dialog-utility. Please install it.
    exit 1
fi

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

 if [ "$MAINSELECT" = "" ]; then
   rm -f /tmp/kgiset
   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 [ "$accel_class"   = "" ]; then clear; exit 1; fi
   if [ "$accel_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 [ "$video_class"   = "" ]; then clear; exit 1; fi
   if [ "$video_type"    = "" ]; then clear; exit 1; fi
   dialog --infobox "Saving configuration..." 5 50
   mv -f .config .config.old 2> /dev/null
   write_conf .config
   rm -f /tmp/kgiset
   clear
   exit
 fi

 if [ "$MAINSELECT" = "AUTO" ]; then
   clear
   ../util/detectcard
   echo "Press enter to continue"
   read FOO
   read_conf
 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=ACCEL
 fi
 if [ "$MAINSELECT" = "ACCEL" ]; then
     accel/.configure $accel_class $accel_type
     accel_class=`cat /tmp/.accelclass`
     accel_type=`cat /tmp/.acceltype`
     rm -f /tmp/.accelclass /tmp/.acceltype
#     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=VIDEO
 fi
 if [ "$MAINSELECT" = "VIDEO" ]; then
     vidio/.configure $video_class $video_type
     video_class=`cat /tmp/.videoclass`
     video_type=`cat /tmp/.videotype`
     rm -f /tmp/.videoclass /tmp/.videotype
 fi

done
