BIOSDIR="$CARDBASEDIR/bios"
PCIPROBEDIR="$CARDBASEDIR/pciprobe"

# This is for easily breaking out of here ...

while true ; do

  #
  # First try PCI-Probing.
  # --------------------------
  echo "Trying to detect your card using the PCI information, if available."
  echo

  . $PCIPROBEDIR/main

  #
  # First try BIOS-detection as this is relatively safe.
  # ----------------------------------------------------
  echo "Unable to detect card by PCI."
  echo "We'll now try detecting your card by the Video BIOS."
  echo "This _might_ cause your machine to hang or reboot."
  echo "If you have any of the following cards the risk for that is very high:"

  cat $BIOSDIR/DANGEROUS

  echo
  echo -n "Do you still want to proceed with the Video BIOS detection? [y/n] "
  read ANS
  if [ "$ANS" = "y" ]; then
    echo "Trying Video BIOS detection."
    echo
    . $BIOSDIR/main
  else
    echo "Skipping Video BIOS detection."
  fi

  #
  # No match. Try SuperProbe.
  # -------------------------
  #
  # Now we try using SuperProbe to detect the card. Maybe this gets us at
  # least near our goal.
  #
  echo
  echo "We cannot detect your card by the BIOS. We will now try using"
  echo "SuperProbe as a last resort."
  SuperProbe | grep -A 100 "First video:" > "$ACBASEDIR/.spresults"
  echo "Superprobe was run and delivered the folowing results:"
  echo
  cat "$ACBASEDIR/.spresults"
  echo
  echo Please note, that SuperProbe information might not suffice to set up
  echo the drivers properly. Most notably the clockchip cannot be detected.
  echo Manual configuration suggested.
  echo

  #
  # We have tried our best, but the card is unknown. We assume plain VGA for
  # that case.
  #
  echo "Sorry. Unable to detect your card. Configuring for IBM vga."
  echo "!! Please run $ACDIR/sysinfo, complete the form and send the results"
  echo "!! to Andreas Beck, <becka@ggi-project.org>."
  echo "!! Your card will then be autodetected in future."

  # reinitialize
  CHIP_CLASS=IBM
  CHIP_TYPE=vga
  ACCEL_CLASS=IBM
  ACCEL_TYPE=vga
  CLK_CLASS=fixed
  CLK_TYPE=vga
  DAC_CLASS=IBM
  DAC_TYPE=vga

  FAILURE=yes

  break

done
