[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: problem with dpkg-reconfigure and noninteractive frontend



On Sat, Apr 24, 2004 at 02:43:25PM -0700, Don Armstrong wrote:
> On Sat, 24 Apr 2004, Denis Barbier wrote:
> > When a package is reconfigured, the new debconf settings and current
> > configuration files are available, but previous debconf settings are
> > not and you cannot determine that there have been no local changes.
> 
> While the former is true[1], the latter is not. See, for example, how
> xserver-xfree86 deals (perhaps suboptimally) with this situation.

It's going to be dealing with it a little less suboptimally in the near
future.

See attachment (you may want to scroll to the bottom).

-- 
G. Branden Robinson                |    It's like I have a shotgun in my
Debian GNU/Linux                   |    mouth, I've got my finger on the
branden@debian.org                 |    trigger, and I like the taste of
http://people.debian.org/~branden/ |    the gunmetal. -- Robert Downey, Jr.
#!/bin/sh
# Debian xserver-xfree86 package configuration script
# Copyright 2000--2004 Branden Robinson.
# Licensed under the GNU General Public License, version 2.  See the file
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.

# $Id: xserver-xfree86.config.in 1188 2004-03-25 23:06:35Z branden $

set -e

# source debconf library
. /usr/share/debconf/confmodule

THIS_PACKAGE=xserver-xfree86
THIS_SCRIPT=config

#INCLUDE_SHELL_LIB#

CONFIG_DIR=/etc/X11
SERVER_SYMLINK="$CONFIG_DIR/X"
XF86CONFIG="$CONFIG_DIR/XF86Config-4"
CONFIG_AUX_DIR=/var/lib/xfree86
SERVER_SYMLINK_CHECKSUM="$CONFIG_AUX_DIR/${SERVER_SYMLINK##*/}.md5sum"
XF86CONFIG_CHECKSUM="$CONFIG_AUX_DIR/${XF86CONFIG##*/}.md5sum"
THIS_SERVER=/usr/bin/X11/XFree86

NCARDS=0
NSERVERS=0
NDRIVERS=0
MULTIHEAD=

# get machine architecture
ARCH=$(dpkg --print-installation-architecture)

discover_video () {
  # wrapper for discover command that can distinguish Discover 1.x and 2.x

  # Ugh, Discover 1.x didn't exit with nonzero status if given an unrecongized
  # option!
  DISCOVER_TEST=$(discover --version 2>/dev/null)
  if expr "$DISCOVER_TEST" : 'discover 2.*' >/dev/null 2>&1; then
    # Discover 2.x
    # XXX: this is sort of nasty
    VENDOR_MODEL_FILE=$(tempfile)
    SERVER_FILE=$(tempfile)
    DRIVER_FILE=$(tempfile)

    CMD="discover --type-summary display"
    run $CMD >$VENDOR_MODEL_FILE
    CMD="discover --data-path=xfree86/server/name \
                  --data-version=${SOURCE_VERSION%-*} display"
    run $CMD >$SERVER_FILE
    CMD="discover --data-path=xfree86/server/device/driver \
                  --data-version=${SOURCE_VERSION%-*} display"
    run $CMD >$DRIVER_FILE

    DISCOVERED_VIDEO=$(paste $VENDOR_MODEL_FILE $SERVER_FILE $DRIVER_FILE)
    rm -f $VENDOR_MODEL_FILE $SERVER_FILE $DRIVER_FILE
  else
    # must be Discover 1.x
    DISCOVERED_VIDEO=$(run discover --disable=serial,parallel \
                                --format="%V %M\t%S\t%D\n" video 2>/dev/null)
  fi
  echo "$DISCOVERED_VIDEO"
}

validate_string_db_input () {
  # Syntax: validate_string_db_input priority template
  #
  # validate string input; can't have doublequotes
  # If $MAY_BE_NULL is a non-null value (e.g., "yes"), the string may be null.
  if [ $# -ne 2 ]; then
    internal_error "validate_string_db_input() called with wrong number of" \
                   "arguments: $*"
  fi
  PRIORITY=$1
  TEMPLATE=$2
  db_get "$TEMPLATE"
  SAFE="$RET"
  set +e
  while :; do
    db_input "$PRIORITY" "$TEMPLATE"
    # is the question going to be asked?
    if [ $? -eq 30 ]; then
      break # no; bail out of validation loop
    fi
    db_go
    db_get "$TEMPLATE"
    if [ -n "$RET" ]; then
      if ! expr "$RET" : '.*".*' >/dev/null 2>&1; then
        break # valid input
      else
        ERROR=xserver-xfree86/config/doublequote_in_string_error
      fi
    else
      if [ -n "$MAY_BE_NULL" ]; then
        break # valid (null) input
      else
        ERROR=xserver-xfree86/config/null_string_error
      fi
    fi
    # we only get to this point if the input was invalid; restore the known
    # good value in case we are interrupted before the user provides a valid
    # one
    db_set "$TEMPLATE" "$SAFE"
    db_fset "$TEMPLATE" seen false
    # now show the user the error message
    db_fset "$ERROR" seen false
    db_input critical "$ERROR"
    db_go
  done
  set -e
}

validate_numeric_db_input () {
  # Syntax: validate_numeric_db_input priority template
  #
  # validate numeric input; must have only digits, can be null
  if [ $# -ne 2 ]; then
    internal_error "validate_numeric_db_input() called with wrong number of" \
                   "arguments: $*"
  fi
  PRIORITY=$1
  TEMPLATE=$2
  db_get "$TEMPLATE"
  SAFE="$RET"
  set +e
  while :; do
    db_input "$PRIORITY" "$TEMPLATE"
    # is the question going to be asked?
    if [ $? -eq 30 ]; then
      break # no; bail out of validation loop
    fi
    db_go
    db_get "$TEMPLATE"
    if [ -z "$RET" ] || expr "$RET" : "[0-9]\+$" >/dev/null 2>&1; then
      break # valid input
    fi
    # we only get to this point if the input was invalid; restore the known
    # good value in case we are interrupted before the user provides a valid
    # one
    db_set "$TEMPLATE" "$SAFE"
    db_fset "$TEMPLATE" seen false
    # now show the user the error message
    db_fset xserver-xfree86/config/nonnumeric_string_error seen false
    db_input critical xserver-xfree86/config/nonnumeric_string_error
    db_go
  done
  set -e
}

validate_bus_id_db_input () {
  # Syntax: validate_bus_id_db_input priority template
  #
  # validate BusID input
  if [ $# -ne 2 ]; then
    internal_error "validate_bus_id_db_input() called with wrong number of" \
                   "arguments: $*"
  fi
  PRIORITY=$1
  TEMPLATE=$2
  db_get "$TEMPLATE"
  SAFE="$RET"
  set +e
  while :; do
    db_input "$PRIORITY" "$TEMPLATE"
    # is the question going to be asked?
    if [ $? -eq 30 ]; then
      break # no; bail out of validation loop
    fi
    db_go
    db_get "$TEMPLATE"
    if [ -z "$RET" ] \
      || expr "$RET" : "[A-Z]\+:[0-9]\{1,3\}:[0-9]\{1,3\}:[0-9]\{1,3\}$" \
      >/dev/null 2>&1; then
      break # valid input
    fi
    # we only get to this point if the input was invalid; restore the known good
    # value in case we are interrupted before the user provides a valid one
    db_set "$TEMPLATE" "$SAFE"
    db_fset "$TEMPLATE" seen false
    # now show the user the error message
    db_fset xserver-xfree86/config/device/bus_id_error seen false
    db_input critical xserver-xfree86/config/device/bus_id_error
    db_go
  done
  set -e
}

validate_monitor_frequency_db_input () {
  # Syntax: validate_monitor_frequency_db_input priority template
  #
  # validate monitor frequency input
  if [ $# -ne 2 ]; then
    internal_error "validate_monitor_frequency_db_input() called with wrong" \
                   "number of arguments: $*"
  fi
  PRIORITY=$1
  TEMPLATE=$2
  db_get "$TEMPLATE"
  SAFE="$RET"
  set +e
  while :; do
    db_input "$PRIORITY" "$TEMPLATE"
    # is the question going to be asked?
    if [ $? -eq 30 ]; then
      break # no; bail out of validation loop
    fi
    db_go
    db_get "$TEMPLATE"
    # string, needs input validation; a simple regex match will have to do;
    # force first character to be a number to avoid hideous problems in the
    # debconf dialog frontend in 0.3.83 (it needs to be one anyway)
    if expr "$RET" : "^[0-9][-0-9,. ]\+$" >/dev/null 2>&1; then
      break # valid input
    fi
    # we only get to this point if the input was invalid; restore the known
    # good value in case we are interrupted before the user provides a
    # valid one
    db_set "$TEMPLATE" "$SAFE"
    db_fset "$TEMPLATE" seen false
    # now show the user the error message
    db_fset xserver-xfree86/config/monitor/range_input_error seen false
    db_input critical xserver-xfree86/config/monitor/range_input_error
    db_go
  done
  set -e
}

auto_answer () {
  # Syntax: auto_answer input_command priority template default_answer
  #
  # Used to auto-answer questions that don't have reasonable defaults.  Some
  # people insist on running the xserver-xfree86 config script with the
  # non-interactive frontend.  For this to work, the debconf database will need
  # to be pre-loaded with answers to several questions.  You have been
  # warned...
  if [ $# -ne 4 ]; then
    internal_error "auto_answer() called with wrong number of arguments: $*"
  fi
  INPUT_COMMAND=$1
  PRIORITY=$2
  TEMPLATE=$3
  DEFAULT_ANSWER=$4
  set +e
  observe "auto_answer() \"$INPUT_COMMAND $PRIORITY $TEMPLATE\" with default" \
          "\"$DEFAULT_ANSWER\""
  # are we re-configuring?
  if [ -n "$RECONFIGURE" ]; then
    # yes, we are reconfiguring
    db_get "$TEMPLATE"
    observe "auto_answer: (reconfiguring) preserving existing answer \"$RET\""
  else
    # not reconfiguring; has the question been seen before?
    db_fget "$TEMPLATE" seen
    if [ "$RET" = "true" ]; then
      db_get "$TEMPLATE"
      observe "auto_answer: (not reconfiguring) preserving existing answer" \
              "\"$RET\""
    else
      observe "auto_answer: auto-answering with \"$DEFAULT_ANSWER\""
      db_set $TEMPLATE "$DEFAULT_ANSWER"
    fi
  fi
  "$INPUT_COMMAND" "$PRIORITY" "$TEMPLATE"
  if [ $? -eq 30 ]; then
    observe "auto_answer: $TEMPLATE is not being asked"
  else
    observe "auto_answer: asking $TEMPLATE"
  fi
  set -e
  db_go
  db_get "$TEMPLATE"
  observe "auto_answer: $TEMPLATE is \"$RET\""
}

set_db_priority () {
  # syntax: set_db_priority requested_priority
  #
  # Given a variable PRIORITY_CEILING and a "requested_priority" argument, set
  # the PRIORITY environment variable to the lesser of the two.

  # Implementation note: a clever version of this could be done using "eval", or
  # embedding a Perl script, but those would be more difficult to maintain.
  # Better just to go the simple and stupid route.  Yes, I know this is not very
  # efficient.

  local priority_ceiling requested_priority

  # Validate arguments.
  if [ $# -ne 1 ]; then
    warn "set_db_priority() called with empty or bogus arguments \"$*\";" \
         "assuming argument of \"low\""
    requested_priority=low
  else
    requested_priority="$1"
  fi

  # If PRIORITY_CEILING is null or unset, it's same as not having one at all;
  # the sky's the limit.  We use a locally scoped priority_ceiling variable
  # because we don't want to affect the value of the global one.
  if [ -n "$PRIORITY_CEILING" ]; then
    priority_ceiling="$PRIORITY_CEILING"
  else
    priority_ceiling=critical
  fi

  # Ensure the value of PRIORITY_CEILING is reasonable.
  if [ "$priority_ceiling" != "critical" ] \
     && [ "$priority_ceiling" != "high" ] \
     && [ "$priority_ceiling" != "medium" ] \
     && [ "$priority_ceiling" != "low" ]; then
    warn "set_db_priority() called with bogus value of \$PRIORITY_CEILING" \
         "\"$PRIORITY_CEILING\"; treating as \"critical\""
    priority_ceiling=critical
  fi

  case "$requested_priority" in
    critical)
      # This is the highest priority, so there is nowhere to go but down.
      PRIORITY="$priority_ceiling"
      ;;
    high)
      case "$priority_ceiling" in
        critical)
          PRIORITY="$requested_priority"
          ;;
        high|medium|low)
          PRIORITY="$priority_ceiling"
          ;;
      esac
      ;;
    medium)
      case "$priority_ceiling" in
        critical|high)
          PRIORITY="$requested_priority"
          ;;
        medium|low)
          PRIORITY="$priority_ceiling"
          ;;
      esac
      ;;
    low)
      # This is the lowest priority, so we can't go any lower.
      PRIORITY="$requested_priority"
      ;;
    *)
      warn "set_db_priority() called with bogus argument" \
           "\"$requested_priority\"; returning \"low\""
      PRIORITY="low"
      ;;
  esac
}

select_default_x_server () {
  # Ask debconf questions that determine the destination of the default X server
  # symbolic link.

  local bailout

  # If the symbolic link to the default X server is under manual control, do
  # nothing.  Perform tests to determine if this is the case.

  # First, assume we're going to be configuring it.
  bailout=

  # Is the symbolic link really a symbolic link?  If not, bail.
  if [ -e "$SERVER_SYMLINK" ] && [ ! -L "$SERVER_SYMLINK" ]; then
    # The symbolic link is not a symbolic link.
    observe "$SERVER_SYMLINK exists but is not a symbolic link"
    bailout=yes
  else
    # Does the symbolic link's checksum exist but not match the actual
    # destination?  If so, bail.
    if [ -e "$SERVER_SYMLINK_CHECKSUM" ]; then
      if [ "$(readlink "$SERVER_SYMLINK" | md5sum)" != \
           "$(cat "$SERVER_SYMLINK_CHECKSUM")" ]; then
        observe "$SERVER_SYMLINK link destination has been manually modified"
        bailout=yes
      fi
    else
      observe "no stored checksum available for $SERVER_SYMLINK"
      bailout=yes
    fi
  fi

  # Bail out now if we're supposed to.
  if [ -n "$bailout" ]; then
    return 1
  fi

  # If the X server symlink file already exists and points to an executable X
  # server, it's not as important to ask questions related to it (these
  # questions "have a reasonable default").
  PRIORITY_CEILING=
  if [ -e "$SERVER_SYMLINK" ]; then
    if [ -x "$(readlink "$SERVER_SYMLINK")" ]; then
      observe "X server symlink exists and points to executable X server;" \
              "capping X server question priority at medium"
      PRIORITY_CEILING=medium
    fi
  fi

  # priority of shared/default-x-server
  set_db_priority "high"

  db_metaget shared/default-x-server owners
  OWNERS="$RET"
  db_metaget shared/default-x-server choices
  CHOICES="$RET"

  if [ "$OWNERS" != "$CHOICES" ]; then
    observe "\$OWNERS does not equal \$CHOICES: \"$OWNERS\" != \"$CHOICES\""
    db_subst shared/default-x-server choices $OWNERS
    db_fset shared/default-x-server seen false
  fi

  if ! expr "$OWNERS" : ".*,.*" >/dev/null 2>&1; then
    observe "\$OWNERS has only one value; shared/default-x-server will not be" \
            "asked"
  fi

  # set a failsafe default answer for shared/default-x-server
  DEFAULT="$THIS_PACKAGE"

  # if configuring for the first time, ask if user wants to autodetect
  if [ -z "$RECONFIGURE" ]; then
    if which discover >/dev/null 2>&1; then
      set_db_priority "medium"
      auto_answer db_input "$PRIORITY" \
        xserver-xfree86/autodetect_video_card "false"
      db_get xserver-xfree86/autodetect_video_card
      AUTODETECT_VIDEO_CARD="$RET"
      if [ "$AUTODETECT_VIDEO_CARD" = "true" ]; then
        if [ $NSERVERS -eq 0 ]; then
          observe "could not autodetect X server: no video card detected, or" \
                  "no server known for it"
          set_db_priority "high"
          run db_input "$PRIORITY" shared/no_known_x-server
          db_go
        elif [ $NSERVERS -eq 1 ]; then
          observe "autodetected X server: $SERVERS"
          if [ "$SERVERS" = "${THIS_SERVER##*/}" ]; then
            # the autodetected X server is the only one on the system, and the
            # one we're currently configuring; it's unlikely the user will want
            # to use something else
            set_db_priority "low"
          else
            observe "X server autodetected, but does not correspond to this" \
                    "package"
            # we do not set shared/default-x-server here, because the
            # autodetected X server might not be getting installed
          fi
        elif [ $NSERVERS -gt 1 ]; then
          observe "could not autodetect X server: multiple servers for video" \
                  "cards"
          VIDEOCARD_SERVER_REPORT=$(echo "$DISCOVERED_VIDEO" \
            | awk 'BEGIN { FS="\t"; printf " %-40s%20s\n .\n", "Detected Video Card", "Suggested X server" } { printf " %-50s%10s\n", $1, $2 } END { printf " .\n" }')
          # can't do this until there is a way to embed newlines into debconf
          # command streams :(
          # db_subst shared/multiple_possible_x-servers detected_cards \
          #   "$VIDEOCARD_SERVER_REPORT"
          observe "$VIDEOCARD_SERVER_REPORT"
          set_db_priority "high"
          run db_input "$PRIORITY" shared/multiple_possible_x-servers
          db_go
        fi
      else
        observe "user declined video card autodetection (server)"
      fi
    else
      observe "could not autodetect X server: discover not found"
    fi
  else
    observe "not prompting for video card autodetection; reconfiguring"
  fi

  # now the default-x-server question may be asked
  db_fget shared/default-x-server seen
  observe "seen flag of shared/default-x-server is $RET"
  observe "db_input $PRIORITY shared/default-x-server"
  auto_answer db_input $PRIORITY shared/default-x-server \
    "$DEFAULT"
}

configure_xfree86_x_server () {
  # Ask debconf questions that determine what XF86Config-4 will look like.

  # TODO: This function should be broken up into several sub-functions, probably
  # roughly mapping to the Section elements of the XF86Config-4 file.  We could
  # then construct a menu of available "functions", and give the user a lot more
  # flexibility in configuring the XFree86 X server with debconf.

  local bailout

  # If the XF86Config-4 configuration file is under manual control, do nothing.
  # Perform tests to determine if this is the case.

  # First, assume we're going to be configuring it.
  bailout=

  # Does the configuration file exist?
  if [ -e "$XF86CONFIG" ]; then
    # If so, check for the existence of the checksum file; if it doesn't exist,
    # the file is under manual control.
    if [ -e "$XF86CONFIG_CHECKSUM" ]; then
      # Compare the current and stored checksums; if they do not match, the
      # file is under manual control.
      if [ "$(md5sum "$XF86CONFIG")" != "$(cat "$XF86CONFIG_CHECKSUM")" ]; then
        observe "$XF86CONFIG file has been customized"
        bailout=yes
      fi
    else
      observe "no stored checksum available for $XF86CONFIG"
      bailout=yes
    fi
  fi

  # Bail out now if we're supposed to.
  if [ -n "$bailout" ]; then
    return 1
  fi

  # if the XFree86 4.x X server configuration file already exists, it's not as
  # important to ask questions related to it (these questions "have a reasonable
  # default")
  PRIORITY_CEILING=
  if [ -e "$XF86CONFIG" ]; then
    observe "$XF86CONFIG file exists; capping configuration question" \
            "priority at medium"
    PRIORITY_CEILING=medium
  fi

  # video driver selection

  # priority of xserver-xfree86/config/device/driver
  set_db_priority "high"

  DRIVER_DIR=/usr/X11R6/lib/modules/drivers

  # Build list of available video drivers, omitting the atimisc, r128, and
  # radeon sub-modules (the ati driver knows when and how to load these).
  # v4l is not a display driver, and dummy is for advanced users.
  DRIVER_LIST="$(echo $(find "$DRIVER_DIR" -name '*_drv.o' 2>/dev/null \
                        | sed 's|^.*/\(.*\)_drv\.o|\1|' \
                        | egrep -v '(atimisc|dummy|r128|radeon|v4l)' | sort) \
                 | sed 's/ /, /g')"

  if [ -z "$DRIVER_LIST" ]; then
    observe "no video driver modules found in $DRIVER_DIR"
  fi

  # Set a hard-coded module list (if necessary) and default driver module on an
  # architecture-specific basis.
  case "$ARCH" in
    alpha)
      DRIVER_LIST=${DRIVER_LIST:=ati, cirrus, glint, mga, nv, rendition, s3, s3virge, savage, siliconmotion, tdfx, tga, vga}
      DEFAULT_DRIVER=vga
      ;;
    arm|hppa)
      DRIVER_LIST=${DRIVER_LIST:=ati, chips, fbdev, glint, mga, nv, s3, s3virge, savage, sis, tdfx, trident, vga}
      DEFAULT_DRIVER=fbdev
      ;;
    hurd-i386)
      DRIVER_LIST=${DRIVER_LIST:=apm, ark, ati, chips, cirrus, cyrix, fbdev, glint, i128, i740, i810, imstt, mga, neomagic, newport, nsc, nv, rendition, s3, s3virge, savage, siliconmotion, sis, tdfx, tga, trident, tseng, vesa, vga, vmware}
      DEFAULT_DRIVER=vesa
      ;;
    i386)
      DRIVER_LIST=${DRIVER_LIST:=apm, ark, ati, chips, cirrus, cyrix, fbdev, glide, glint, i128, i740, i810, imstt, mga, neomagic, newport, nsc, nv, rendition, s3, s3virge, savage, siliconmotion, sis, tdfx, tga, trident, tseng, vesa, vga, vmware}
      DEFAULT_DRIVER=vesa
      ;;
    ia64)
      DRIVER_LIST=${DRIVER_LIST:=apm, ark, ati, chips, cirrus, cyrix, fbdev, glint, i128, i740, i810, imstt, mga, neomagic, newport, nv, rendition, s3, s3virge, savage, siliconmotion, sis, tdfx, tga, trident, tseng, vesa, vga, vmware}
      DEFAULT_DRIVER=fbdev
      ;;
    m68k|powerpc)
      DRIVER_LIST=${DRIVER_LIST:=ati, chips, fbdev, glint, imstt, mga, nv, s3, s3virge, savage, sis, tdfx, trident, vga}
      DEFAULT_DRIVER=fbdev
      ;;
    mips|mipsel)
     DRIVER_LIST=${DRIVER_LIST:=ati, chips, fbdev, glint, mga, newport, nv, s3, s3virge, savage, sis, tdfx, trident}
     DEFAULT_DRIVER=fbdev
      ;;
    sparc)
      DRIVER_LIST=${DRIVER_LIST:=apm, ark, ati, chips, cirrus, fbdev, glint, i128, i740, imstt, mga, neomagic, nv, rendition, s3virge, savage, siliconmotion, sunbw2, suncg14, suncg3, suncg6, sunffb, sunleo, suntcx, tdfx, trident, vesa, vga}
      DEFAULT_DRIVER=fbdev
      ;;
    *)
      internal_error "no driver list known for architecture $ARCH"
      ;;
  esac

  observe "available video driver list set to \"$DRIVER_LIST\""

  # attempt to autodetect
  if which discover >/dev/null 2>&1; then
    if [ "$AUTODETECT_VIDEO_CARD" = "true" ]; then
      if [ $NDRIVERS -eq 0 ]; then
        observe "could not autodetect X server driver: no video card" \
                "detected, or no driver known for it"
      elif [ $NDRIVERS -eq 1 ]; then
        observe "autodetected X server driver: $DRIVERS"
        set_db_priority "low"
        DEFAULT_DRIVER="$DRIVERS"
      elif [ $NDRIVERS -gt 1 ]; then
        observe "could not autodetect X server driver: multiple drivers for" \
                "video cards"
        VIDEOCARD_DRIVER_REPORT=$(echo "$DISCOVERED_VIDEO" \
          | awk 'BEGIN { FS="\t"; printf " %-30s%30s\n .\n", "Detected Video Card", "Suggested driver module" } { printf " %-50s%10s\n", $1, $3 } END { printf " .\n" }')
        # can't do this until there is a way to embed newlines into debconf
        # command streams :(
        # db_subst shared/multiple_possible_x-drivers detected_cards \
        #   "$VIDEOCARD_DRIVER_REPORT"
        observe "$VIDEOCARD_DRIVER_REPORT"
        set_db_priority "high"
        run db_input "$PRIORITY" xserver-xfree86/multiple_possible_x-drivers
        db_go
      fi
    else
      observe "user declined video card autodetection (driver)"
    fi
  else
    observe "could not autodetect X server driver: discover not found"
  fi

  db_subst xserver-xfree86/config/device/driver choices "$DRIVER_LIST"
  auto_answer db_input "$PRIORITY" \
    xserver-xfree86/config/device/driver "$DEFAULT_DRIVER"

  # card identifier; try to set a sensible default
  DEFAULT=
  if [ -n "$NDRIVERS" ] && [ -n "$NCARDS" ] && [ $NDRIVERS -eq 1 ] \
     && [ $NCARDS -eq 1 ]; then
    if which discover >/dev/null 2>&1; then
      if [ "$AUTODETECT_VIDEO_CARD" = "true" ]; then
        DEFAULT=$(echo "$DISCOVERED_VIDEO" | cut -f1)
      fi
    fi
  fi
  if [ -z "$DEFAULT" ]; then
    # fall back to some language-specific generic text
    # TODO: make this a read-only debconf template
    case "${LC_ALL:-${LC_MESSAGES:-$LANG}}" in
      ca_*) DEFAULT="Targeta de v�o gen�ca" ;;
      # da
      de_*) DEFAULT="Standardgrafikkarte" ;;
      es_*) DEFAULT="Tarjeta de v�o gen�ca" ;;
      fr_*) DEFAULT="Carte vid�g�rique" ;;
      gl_*) DEFAULT="Tarxeta de Video Xen�ca" ;;
      it_*) DEFAULT="Scheda video generica" ;;
      # ja
      # nl
      pt_BR) DEFAULT="Placa de V�o Gen�ca" ;;
      # ru
      # sv
      *) DEFAULT="Generic Video Card" ;;
    esac
  fi
  set_db_priority "low"
  # this question requires input validation
  MAY_BE_NULL= auto_answer validate_string_db_input "$PRIORITY" \
    xserver-xfree86/config/device/identifier "$DEFAULT"

  # BusID
  set_db_priority "low"
  DEFAULT=
  if [ "$ARCH" = "powerpc" ] || [ "$MULTIHEAD" = "yes" ]; then
    if [ "$ARCH" = "powerpc" ]; then
      set_db_priority "medium"
    fi
    if [ "$MULTIHEAD" = "yes" ]; then
      set_db_priority "high"
    fi
    if which lspci >/dev/null 2>&1; then
      # try to guess the correct BusID
      VIDEO_CARD=$(LC_ALL=C lspci -n | grep "Class 0300:" | head -n 1 \
                   | cut -d\  -f1)
      if [ -n "$VIDEO_CARD" ]; then
        # we now have an entry in "hex:hex.hex" format, need
        # "PCI:decimal:decimal:decimal"
        BUS=$(printf "%d" 0x$(echo $VIDEO_CARD | cut -d: -f1) )
        DEVICE=$(printf "%d" 0x$(echo $VIDEO_CARD | cut -d: -f2 | cut -d. -f1) )
        FUNCTION=$(printf "%d" 0x$(echo $VIDEO_CARD | cut -d. -f2) )
        DEFAULT=PCI:$BUS:$DEVICE:$FUNCTION
      fi
    fi
  fi
  # this question requires input validation
  if [ -n "$DEFAULT" ]; then
    auto_answer validate_bus_id_db_input "$PRIORITY" \
      xserver-xfree86/config/device/bus_id "$DEFAULT"
  else
    run validate_bus_id_db_input "$PRIORITY" \
      xserver-xfree86/config/device/bus_id
  fi

  set_db_priority "low"
  # this question requires input validation
  run validate_numeric_db_input "$PRIORITY" \
    xserver-xfree86/config/device/video_ram

  # Use fbcon kernel interface?
  set_db_priority "high"
  case "$ARCH" in
    alpha|hurd-i386|i386)
      DEFAULT_USEFBDEV=false
      ;;
    *)
      DEFAULT_USEFBDEV=true
      ;;
  esac

  DEFAULT_USEFBDEV=
  # XXX: is this a good test for /proc being mounted?
  if [ -e /proc/self ]; then
    if [ -e /proc/fb ]; then
      FB_TYPE="$(grep '^0 ' /proc/fb | sed 's/[^[:space:]] //')"
      observe "/proc/fb reports framebuffer type \"$FB_TYPE\""
      # did we actually get back anything?
      if [ -n "$FB_TYPE" ]; then
        set_db_priority "medium"
        case "$FB_TYPE" in
          OFfb|VESA)
            observe "this framebuffer type does not support UseFBDev"
            DEFAULT_USEFBDEV=false
            ;;
          *)
            # other framebuffers do support UseFBDev
            DEFAULT_USEFBDEV=true
            ;;
        esac
      fi
    else
      observe "/proc/fb does not exist; assuming fbcon not in use"
    fi
  else
    observe "/proc not mounted; cannot determine if fbcon in use"
  fi

  # re-set the default answer to false if need be
  run db_get xserver-xfree86/config/device/use_fbdev
  if [ "$RET" = "true" ] && [ "$DEFAULT_USEFBDEV" = "false" ]; then
    observe "xserver-xfree86/config/device/use_fbdev is \"true\" but" \
            "/proc/fb does not exist, is empty, or reports a framebuffer" \
            "type with which UseFBDev cannot be used; setting template to" \
            "\"false\""
    db_set xserver-xfree86/config/device/use_fbdev false
  fi

  auto_answer db_input "$PRIORITY" xserver-xfree86/config/device/use_fbdev \
    "$DEFAULT_USEFBDEV"

  # keyboard setup

  # TODO: query of debian-installer's keyboard configuration debconf template
  # goes here

  # these questions require input validation
  set_db_priority "medium"

  if [ "$ARCH" = "sparc" ]; then
    DEFAULT=sun
  else
    DEFAULT=xfree86
  fi
  MAY_BE_NULL= auto_answer validate_string_db_input \
    "$PRIORITY" \
    xserver-xfree86/config/inputdevice/keyboard/rules "$DEFAULT"

  db_get xserver-xfree86/config/inputdevice/keyboard/rules
  if [ "$RET" = "sun" ]; then
    DEFAULT=type5
  elif [ "$RET" = "xfree86" ]; then
    if [ "$ARCH" = "powerpc" ]; then
      DEFAULT=macintosh
      # good old-fashioned BRAIN DAMAGE
      if [ -e /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes ]; then
        if [ "$(cat /proc/sys/dev/mac_hid/keyboard_sends_linux_keycodes)" \
             = "0" ]; then
          DEFAULT=macintosh_old
        fi
      fi
    else
      DEFAULT=pc104
    fi
  fi
  MAY_BE_NULL= auto_answer validate_string_db_input \
    "$PRIORITY" \
    xserver-xfree86/config/inputdevice/keyboard/model "$DEFAULT"

  MAY_BE_NULL= auto_answer validate_string_db_input \
    "$PRIORITY" \
    xserver-xfree86/config/inputdevice/keyboard/layout "us"

  db_get xserver-xfree86/config/inputdevice/keyboard/layout
  if [ "$RET" != "us" ]; then
    set_db_priority "medium"
  else
    set_db_priority "low"
  fi
  MAY_BE_NULL=yes validate_string_db_input \
    "$PRIORITY" \
    xserver-xfree86/config/inputdevice/keyboard/variant

  MAY_BE_NULL=yes validate_string_db_input \
    "$PRIORITY" \
    xserver-xfree86/config/inputdevice/keyboard/options

  # mouse device detection

  # priority of xserver-xfree86/config/inputdevice/mouse/{port,protocol}
  set_db_priority "high"
  AUTODETECTED_PORT=
  AUTODETECTED_PROTOCOL=

  # determine if we're using devfs
  if [ -c /dev/.devfsd ]; then
    USING_DEVFS=true
  else
    USING_DEVFS=
  fi

  if [ -n "$USING_DEVFS" ]; then
    MOUSE_PORT_CHOICES="/dev/misc/psaux, /dev/tts/0, /dev/tts/1, /dev/tts/2, /dev/tts/3, /dev/input/mice, /dev/misc/atixl, /dev/gpmdata"
    DEFAULT_PORT="/dev/misc/psaux"
  else
    MOUSE_PORT_CHOICES="/dev/psaux, /dev/ttyS0, /dev/ttyS1, /dev/ttyS2, /dev/ttyS3, /dev/input/mice, /dev/atibm, /dev/sunmouse, /dev/gpmdata"
    DEFAULT_PORT="/dev/psaux"
  fi

  # if configuring for the first time, ask if user wants to autodetect
  if [ -z "$RECONFIGURE" ]; then
    while :; do
      # bail out if autodetection tool not available
      which mdetect >/dev/null 2>&1 || break
      auto_answer db_input "$PRIORITY" \
        xserver-xfree86/autodetect_mouse "false"
      db_get xserver-xfree86/autodetect_mouse
      if [ "$RET" = "true" ]; then
        MDETECT_OUTPUT=$(run mdetect -x)
        if [ -n "$MDETECT_OUTPUT" ]; then
          if [ $(echo "$MDETECT_OUTPUT" | wc -l) -ne 2 ]; then
            observe "bug in mdetect; did not return two lines of output"
            break
          fi
          AUTODETECTED_PORT=$(echo "$MDETECT_OUTPUT" | head -n 1)
          AUTODETECTED_PROTOCOL=$(echo "$MDETECT_OUTPUT" | tail -n 1)
          observe "mdetect returned port \"$AUTODETECTED_PORT\"; protocol" \
                  "\"$AUTODETECTED_PROTOCOL\""
          if [ -n "$AUTODETECTED_PORT" ]; then
            # /dev/input/mouse* means we autodetected a USB pointer; we will
            # store /dev/input/mice instead.
            if expr "$AUTODETECTED_PORT" : "/dev/input/mouse.*" >/dev/null \
              2>&1; then
              AUTODETECTED_PORT="/dev/input/mice"
            fi
          else
            observe "bug in mdetect: returned nothing for mouse port"
            break
          fi
          if [ -z "$AUTODETECTED_PROTOCOL" ]; then
            observe "bug in mdetect: returned nothing for mouse protocol"
            break
          fi
        else
          observe "mdetect returned no output; unable to autodetect mouse"
          # permit user to retry, but set to false in the case question doesn't
          # get asked (for noninteractive configuration)
          db_set xserver-xfree86/autodetect_mouse "false"
        fi
        if [ -n "$AUTODETECTED_PORT" ] && [ -n "$AUTODETECTED_PROTOCOL" ]; then
          set_db_priority "medium"
          break # port and protocol determined
        fi
      else
        observe "user declined mouse autodetection"
        break # bail out; autodetection not desired
      fi
    done
  else
    observe "not prompting for mouse autodetection; reconfiguring"
  fi

  db_subst xserver-xfree86/config/inputdevice/mouse/port choices \
    "$MOUSE_PORT_CHOICES"
  auto_answer db_input "$PRIORITY" \
    xserver-xfree86/config/inputdevice/mouse/port \
    "${AUTODETECTED_PORT:-$DEFAULT_PORT}"

  db_get xserver-xfree86/config/inputdevice/mouse/port
  case "$RET" in
    *psaux)
      MOUSE_PROTOCOL_CHOICES="PS/2, ImPS/2, GlidePointPS/2, NetMousePS/2, NetScrollPS/2, ThinkingMousePS/2, MouseManPlusPS/2, ExplorerPS/2"
      DEFAULT_PROTOCOL="PS/2"
      ;;
    *ttyS*|*tts/*)
      MOUSE_PROTOCOL_CHOICES="Auto, Microsoft, MouseSystems, GlidePoint, ThinkingMouse, MouseMan, Logitech, IntelliMouse, MMSeries, MMHitTab"
      DEFAULT_PROTOCOL="Auto"
      ;;
    *input/mice)
      MOUSE_PROTOCOL_CHOICES="ImPS/2"
      DEFAULT_PROTOCOL="ImPS/2"
      ;;
    *atibm|*atixl|*sunmouse)
      MOUSE_PROTOCOL_CHOICES="BusMouse"
      DEFAULT_PROTOCOL="BusMouse"
      ;;
    *gpmdata)
      MOUSE_PROTOCOL_CHOICES="IntelliMouse"
      DEFAULT_PROTOCOL="IntelliMouse"
      ;;
  esac
  db_subst xserver-xfree86/config/inputdevice/mouse/protocol choices \
    "$MOUSE_PROTOCOL_CHOICES"
  if ! expr "$MOUSE_PROTOCOL_CHOICES" : ".*,.*" >/dev/null 2>&1; then
    observe "\$MOUSE_PROTOCOL_CHOICES has only one value; setting" \
            "xserver-xfree86/config/inputdevice/mouse/protocol to" \
            "\"$DEFAULT_PROTOCOL\""
    db_set xserver-xfree86/config/inputdevice/mouse/protocol "$DEFAULT_PROTOCOL"
  else
    auto_answer db_input "$PRIORITY" \
      xserver-xfree86/config/inputdevice/mouse/protocol \
      "${AUTODETECTED_PROTOCOL:-$DEFAULT_PROTOCOL}"
  fi

  set_db_priority "low"
  run db_input "$PRIORITY" \
    xserver-xfree86/config/inputdevice/mouse/emulate3buttons
  run db_input "$PRIORITY" \
    xserver-xfree86/config/inputdevice/mouse/zaxismapping
  db_go

  # monitor setup
  set_db_priority "high"
  DEFAULT_HORIZ_SYNC="28-50"
  DEFAULT_VERT_REFRESH="43-75"

  db_fget xserver-xfree86/config/monitor/identifier seen
  if [ "$RET" = "false" ]; then
    observe "xserver-xfree86/config/monitor/identifier has not been seen"
  fi

  db_get xserver-xfree86/config/monitor/identifier
  observe "xserver-xfree86/config/monitor/identifier is already set to \"$RET\""

  # The horiz-sync and vert-refresh questions may have answers even though they
  # haven't been seen; autodetection, pre-loading, and the simple and medium
  # selection methods can fill them in.

  db_fget xserver-xfree86/config/monitor/horiz-sync seen
  if [ "$RET" = "false" ]; then
    observe "xserver-xfree86/config/monitor/horiz-sync has not been seen"
  fi

  db_get xserver-xfree86/config/monitor/horiz-sync
  observe "xserver-xfree86/config/monitor/horiz-sync is already set to \"$RET\""

  db_fget xserver-xfree86/config/monitor/vert-refresh seen
  if [ "$RET" = "false" ]; then
    observe "xserver-xfree86/config/monitor/vert-refresh has not been seen"
  fi

  db_get xserver-xfree86/config/monitor/vert-refresh
  observe "xserver-xfree86/config/monitor/vert-refresh is already set to" \
          "\"$RET\""

  # if configuring for the first time, ask if user wants to autodetect
  if [ -z "$RECONFIGURE" ]; then
    if which get-edid >/dev/null 2>&1; then
      auto_answer db_input "$PRIORITY" \
        xserver-xfree86/autodetect_monitor "false"
      db_get xserver-xfree86/autodetect_monitor
      if [ "$RET" = "true" ]; then
        set +e
        EDID_DUMP=$( (get-edid | parse-edid) 2>/dev/null)
        set -e
        if [ $? -eq 0 ]; then
          # quite crude
          MONITOR_IDENTIFIER=$(echo "$EDID_DUMP" | grep Identifier \
            | cut -f2 -d\")
          if [ -n "$MONITOR_IDENTIFIER" ]; then
            observe "get-edid reports monitor identifier of" \
                    "\"$MONITOR_IDENTIFIER\""
            DEFAULT_MONITOR_IDENTIFIER="$MONITOR_IDENTIFIER"
          else
            observe "got null monitor identifier from get-edid"
          fi
          # even cruder
          HORIZ_SYNC=$(echo "$EDID_DUMP" | grep HorizSync | awk '{print $2}')
          VERT_REFRESH=$(echo "$EDID_DUMP" | grep VertRefresh \
            | awk '{print $2}')
          # get-edid may succeed but be unable to return info anyway
          if [ -n "$HORIZ_SYNC" ]; then
            observe "get-edid reports horizonal sync of \"$HORIZ_SYNC\""
            DEFAULT_HORIZ_SYNC="$HORIZ_SYNC"
          else
            observe "get-edid returned blank hsync"
          fi
          if [ -n "$VERT_REFRESH" ]; then
            observe "get-edid reports vertical refresh of \"$VERT_REFRESH\""
            DEFAULT_VERT_REFRESH="$VERT_REFRESH"
          else
            observe "get-edid returned blank vrefresh"
          fi
        else
          observe "get-edid returned an error"
        fi
      else
        observe "user declined monitor autodetection"
      fi
    else
      observe "could not autodetect monitor frequencies; get-edid not found"
    fi
  else
    observe "not prompting for monitor autodetection; reconfiguring"
  fi

  # priority of xserver-xfree86/config/monitor/identifier
  set_db_priority "low"

  # monitor identifier; try to set a sensible default
  if [ -n "$DEFAULT_MONITOR_IDENTIFIER" ]; then
    DEFAULT="$DEFAULT_MONITOR_IDENTIFIER"
  else
    # fall back to some language-specific generic text
    # TODO: make this a read-only debconf template
    case "${LC_ALL:-${LC_MESSAGES:-$LANG}}" in
      ca_*) DEFAULT="Monitor gen�c" ;;
      # da
      de_*) DEFAULT="Standardbildschirm" ;;
      es_*) DEFAULT="Monitor gen�co" ;;
      # fr
      # gl
      it_*) DEFAULT="Monitor Generico" ;;
      # ja
      # nl
      pt_BR) DEFAULT="Monitor Gen�co" ;;
      # ru
      # sv
      *) DEFAULT="Generic Monitor" ;;
    esac
  fi
  # this question requires input validation
  MAY_BE_NULL= auto_answer validate_string_db_input \
    "$PRIORITY" xserver-xfree86/config/monitor/identifier \
    "$DEFAULT"

  # priority of xserver-xfree86/config/monitor/selection-method
  set_db_priority "medium"

  if [ -n "$HORIZ_SYNC" ] && [ -n "$VERT_REFRESH" ]; then
    observe "\$HORIZ_SYNC: \"$HORIZ_SYNC\" ; \$VERT_REFRESH:" \
            "\"$VERT_REFRESH\"; setting question priority to low"
    set_db_priority "low"
  else
    observe "at least of one of hsync \"$HORIZ_SYNC\" or vrefresh" \
            "\"$VERT_REFRESH\" is null; not setting question priority to low"
  fi

  observe "monitor hsync and vrefresh question priority is $PRIORITY"

  auto_answer db_input "$PRIORITY" \
    xserver-xfree86/config/monitor/lcd "false"
  db_get xserver-xfree86/config/monitor/lcd
  observe "xserver-xfree86/config/monitor/lcd is $RET"
  MONITOR_IS_LCD="$RET"
  if [ "$RET" = "true" ]; then
    db_subst xserver-xfree86/config/monitor/selection-method choices \
      "Medium, Advanced"
  else # not an LCD
    db_subst xserver-xfree86/config/monitor/selection-method choices \
      "Simple, Medium, Advanced"
  fi

  # Flat panels are more and more common, so set the default to medium.
  db_subst xserver-xfree86/config/monitor/selection-method default "Medium"

  run db_input "$PRIORITY" xserver-xfree86/config/monitor/selection-method

  # priority of xserver-xfree86/config/monitor/{several things}
  set_db_priority "high"

  db_get xserver-xfree86/config/monitor/selection-method
  case "$RET" in
    Simple)
      run db_input "$PRIORITY" \
        xserver-xfree86/config/monitor/screen-size
      db_go
      db_get xserver-xfree86/config/monitor/screen-size
      case "$RET" in
        'Up to 14 inches (355 mm)')
          db_set xserver-xfree86/config/monitor/horiz-sync "28-33"
          db_set xserver-xfree86/config/monitor/vert-refresh "43-72"
          ;;
        '15 inches (380 mm)')
          db_set xserver-xfree86/config/monitor/horiz-sync "28-50"
          db_set xserver-xfree86/config/monitor/vert-refresh "43-75"
          ;;
        '17 inches (430 mm)')
          db_set xserver-xfree86/config/monitor/horiz-sync "30-70"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-160"
          ;;
        '19-20 inches (480-510 mm)')
          db_set xserver-xfree86/config/monitor/horiz-sync "30-100"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-160"
          ;;
        '21 inches (530 mm) or more')
          db_set xserver-xfree86/config/monitor/horiz-sync "30-130"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-160"
          ;;
      esac
      ;;
    Medium)
      run db_input "$PRIORITY" \
        xserver-xfree86/config/monitor/mode-list
      db_go
      db_get xserver-xfree86/config/monitor/mode-list
      case "$RET" in
        "640x480 @ 60Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "28-33"
          db_set xserver-xfree86/config/monitor/vert-refresh "43-72"
          DEFAULT_MODES="640x480"
          ;;
        "640x480 @ 72Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "28-38"
          db_set xserver-xfree86/config/monitor/vert-refresh "43-72"
          DEFAULT_MODES="640x480"
          ;;
        "800x600 @ 60Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "28-38"
          db_set xserver-xfree86/config/monitor/vert-refresh "43-72"
          DEFAULT_MODES="800x600"
          ;;
        "800x600 @ 72Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "28-48"
          db_set xserver-xfree86/config/monitor/vert-refresh "43-72"
          DEFAULT_MODES="800x600"
          ;;
        "800x600 @ 85Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-54"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-85"
          DEFAULT_MODES="800x600"
          ;;
        "1024x768 @ 60Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "28-49"
          db_set xserver-xfree86/config/monitor/vert-refresh "43-72"
          DEFAULT_MODES="1024x768"
          ;;
        "1024x768 @ 70Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-57"
          db_set xserver-xfree86/config/monitor/vert-refresh "43-72"
          DEFAULT_MODES="1024x768"
          ;;
        "1024x768 @ 75Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-60"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-75"
          DEFAULT_MODES="1024x768"
          ;;
        "1152x864 @ 75Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-68"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-85"
          DEFAULT_MODES="1152x864"
          ;;
        "1280x960 @ 60Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-60"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-75"
          DEFAULT_MODES="1280x960"
          ;;
        "1280x960 @ 85Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-92"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-85"
          DEFAULT_MODES="1280x960"
          ;;
        "1600x1200 @ 60Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-75"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-85"
          DEFAULT_MODES="1600x1200"
          ;;
        "1600x1200 @ 75Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-94"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-75"
          DEFAULT_MODES="1600x1200"
          ;;
        "1600x1200 @ 85Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-107"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-85"
          DEFAULT_MODES="1600x1200"
          ;;
        "1792x1344 @ 75Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-107"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-85"
          DEFAULT_MODES="1792x1344"
          ;;
        "1792x1344 @ 60Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-84"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-75"
          DEFAULT_MODES="1792x1344"
          ;;
        "1856x1392 @ 60Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-87"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-75"
          DEFAULT_MODES="1856x1392"
          ;;
        "1856x1392 @ 75Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-113"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-75"
          DEFAULT_MODES="1856x1392"
          ;;
        "1920x1440 @ 60Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-90"
          db_set xserver-xfree86/config/monitor/vert-refresh "50-75"
          DEFAULT_MODES="1920x1440"
          ;;
        "1920x1440 @ 75Hz")
          db_set xserver-xfree86/config/monitor/horiz-sync "30-130"
          db_set xserver-xfree86/config/monitor/vert-refresh "60-160"
          DEFAULT_MODES="1920x1440"
          ;;
      esac
      ;;
    Advanced)
      auto_answer validate_monitor_frequency_db_input \
        "$PRIORITY" \
        xserver-xfree86/config/monitor/horiz-sync "28-50"
      auto_answer validate_monitor_frequency_db_input \
        "$PRIORITY" \
        xserver-xfree86/config/monitor/vert-refresh "43-75"
      ;;
  esac

  # Configure available video modes.  For certain drivers we will override any
  # existing value of $DEFAULT_MODES, because they only support certain modes.
  # Otherwise, the existing value of $DEFAULT_MODES is preserved.
  db_get xserver-xfree86/config/device/driver
  case "$RET" in
    newport)
      DEFAULT_DEPTH=8
      DEFAULT_MODES="1280x1024"
      ;;
    vga)
      DEFAULT_DEPTH=4
      DEFAULT_MODES="640x480"
      ;;
    *)
      DEFAULT_DEPTH=24
      DEFAULT_MODES=${DEFAULT_MODES:="800x600, 640x480"}
      ;;
  esac

  observe "\"xserver-xfree86/config/device/driver\" is \"$RET\"; set default" \
          "color depth to $DEFAULT_DEPTH and available video modes to" \
          "\"$DEFAULT_MODES\""

  set_db_priority "medium"

  # list of desired display modes
  auto_answer db_input "$PRIORITY" xserver-xfree86/config/display/modes \
    "$DEFAULT_MODES"

  # default display depth
  auto_answer db_input "$PRIORITY" \
    xserver-xfree86/config/display/default_depth "$DEFAULT_DEPTH"

  # server modules to load
  db_get xserver-xfree86/config/device/driver
  set_db_priority "low"
  db_input "$PRIORITY" xserver-xfree86/config/modules
  db_go

  # files and dri sections
  run db_input "$PRIORITY" xserver-xfree86/config/write_files_section
  run db_input "$PRIORITY" xserver-xfree86/config/write_dri_section
  db_go
}

# analyze arguments; used by auto_answer()
if [ "$1" = "reconfigure" ] || [ -n "$2" ]; then
  # if we are reconfiguring, or already have installed the package at least
  # once before, we should not let auto_answer stomp on existing answers to
  # debconf questions
  observe "package being reconfigured"
  RECONFIGURE=true
else
  RECONFIGURE=
fi

# migrate from old select-type templates
for TEMPLATE in xserver-xfree86/config/inputdevice/mouse/emulate3buttons \
                xserver-xfree86/config/inputdevice/mouse/zaxismapping; do
  db_get "$TEMPLATE"
  if [ "$RET" = "Yes" ]; then
    observe "migrating template \"$TEMPLATE\" from \"Yes\" to \"true\""
    db_set $TEMPLATE "true"
  elif [ "$RET" = "No" ]; then
    observe "migrating template \"$TEMPLATE\" from \"No\" to \"false\""
    db_set $TEMPLATE "false"
  fi
done

# migrate from "expert" to "advanced"
db_get xserver-xfree86/config/monitor/selection-method
if [ "$RET" = "Expert" ]; then
  observe "migrating template" \
          "\"xserver-xfree86/config/monitor/selection-method\" from" \
          "\"Expert\" to \"Advanced\""
  db_set xserver-xfree86/config/monitor/selection-method "Advanced"
fi

# migrate to XFree86 4.2 or later, where there are no pex or xie modules
db_get xserver-xfree86/config/modules
SELECTED_MODULES="$(echo $RET | awk 'BEGIN { RS=", "} {print $1}')"
# are the pex or xie modules selected?
if echo "$SELECTED_MODULES" | egrep -q "(pex|xie)"; then
  observe "removing pex and xie modules from list of selected modules"
  observe "old value of template \"xserver-xfree86/config/modules\": \"$RET\""
  # get rid of them
  SELECTED_MODULES=$(echo "$SELECTED_MODULES" | egrep -v "(pex|xie)")
  SELECTED_MODULES=$(echo $SELECTED_MODULES | sed 's/ /, /g')
  db_set xserver-xfree86/config/modules "$SELECTED_MODULES"
  db_get xserver-xfree86/config/modules
  observe "new value of template \"xserver-xfree86/config/modules\": \"$RET\""
fi

# migrate from ATI driver sub-modules to ATI driver
db_get xserver-xfree86/config/device/driver
case "$RET" in
  atimisc|r128|radeon)
    observe "migrating template \"xserver-xfree86/config/device/driver\" from" \
            "\"$RET\" to \"ati\""
    db_set xserver-xfree86/config/device/driver "ati"
    ;;
  *)
    ;;
esac

# The only supported protocol (per Zephaniah Hull) for the GPM repeater is
# IntelliMouse; migrate anyone using that mouse device to that protocol.  Other
# values used to work as well, but no longer do since the XFree86 mouse driver
# was rewritten for XFree86 4.3.0.  See Debian bug #233933 for more details.
db_get xserver-xfree86/config/inputdevice/mouse/port
if [ "$RET" = "/dev/gpmdata" ]; then
  db_get xserver-xfree86/config/inputdevice/mouse/protocol
  if [ "$RET" != "IntelliMouse" ]; then
    observe "migrating template" \
            "\"xserver-xfree86/config/inputdevice/mouse/protocol\" from" \
            "\"$RET\" to \"IntelliMouse\""
    db_set xserver-xfree86/config/inputdevice/mouse/protocol "IntelliMouse"
  fi
fi

# collect information about installed video card(s), if possible
if which discover >/dev/null 2>&1; then
  DISCOVERED_VIDEO=$(discover_video)
  if [ -n "$DISCOVERED_VIDEO" ]; then
    NCARDS=$(echo "$DISCOVERED_VIDEO" | wc -l | tr -d '[:blank:]')
    SERVERS=$(echo "$DISCOVERED_VIDEO" | cut -f2 | grep -v unknown | sort -u)
    NSERVERS=$(echo "$SERVERS" | wc -l | tr -d '[:blank:]')
    DRIVERS=$(echo "$DISCOVERED_VIDEO" | cut -f3 | grep -v unknown | sort -u)
    NDRIVERS=$(echo "$DRIVERS" | wc -l | tr -d '[:blank:]')
    if [ $NCARDS -gt 1 ]; then
      MULTIHEAD=yes
    fi
  else
    observe "discover reported nothing"
  fi
else
  observe "discover command not available"
fi

# select default X server

SKIP_XFREE86_X_SERVER_CONFIG=
if select_default_x_server; then
  # is this the selected X server?
  db_get shared/default-x-server
  if [ "$RET" != "$THIS_PACKAGE" ]; then
    # nothing else to do in this script
    observe "skipping further configuration of $THIS_PACKAGE; it is not the" \
            "default X server package"
    SKIP_XFREE86_X_SERVER_CONFIG=yes
  fi
else
  if [ -n "$RECONFIGURE" ]; then
    warn "not reconfiguring default X server; manual modifications have been" \
         "made --- please see /usr/share/doc/xfree86-common/FAQ.gz"
  else
    observe "not configuring default X server; manual modifications have been" \
         "made --- please see /usr/share/doc/xfree86-common/FAQ.gz"
  fi
fi

# configure XFree86 X server

# Do not be tempted to move this into the "if select_default_x_server" block
# above; we want to permit the user to reconfigure the XF86Config-4 file even if
# the default X server is being handled manually.

if [ -z "$SKIP_XFREE86_X_SERVER_CONFIG" ]; then
  if ! configure_xfree86_x_server; then
    if [ -n "$RECONFIGURE" ]; then
      warn "not reconfiguring XFree86 X server; manual modifications have" \
           "been made --- please see /usr/share/doc/xfree86-common/FAQ.gz"
    else
      observe "not configuring XFree86 X server; manual modifications have" \
              "been made --- please see /usr/share/doc/xfree86-common/FAQ.gz"
    fi
  fi
fi

exit 0

# vim:set ai et sts=2 sw=2 tw=80:

Attachment: signature.asc
Description: Digital signature


Reply to: