#!/bin/sh -e

# Versioning
version=4:2.2.1

# Use debconf baby
. /usr/share/debconf/confmodule

THIS_PACKAGE=kdm
DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager
# set default display manager
 
db_get shared/default-x-display-manager
OLD_DEFAULT="$RET"
 
db_metaget shared/default-x-display-manager owners
OWNERS="$RET"
db_metaget shared/default-x-display-manager choices
CHOICES="$RET"

if [ "$OWNERS" != "$CHOICES" ]; then
  db_subst shared/default-x-display-manager choices $OWNERS
  db_fset shared/default-x-display-manager isdefault true
fi

db_input high shared/default-x-display-manager || true
db_go

# using this display manager?
db_get shared/default-x-display-manager
CURRENT_DEFAULT="$RET"

if [ "$CURRENT_DEFAULT" = "$THIS_PACKAGE" ]; then
  db_input medium kdm/default_nolisten_udp || true
  db_input medium kdm/default_servers_100dpi || true
  db_input medium kdm/default_servers_nolisten_tcp || true
  db_go
  if [ "$OLD_DEFAULT" != "$CURRENT_DEFAULT" ]; then
  # remove the default display manager file since we're going to change it
  rm -f $DEFAULT_DISPLAY_MANAGER_FILE
  fi
fi

exit 0
