#! /bin/sh -e
# Only if gdm is used as default-display-manager, configure it.
if [ $(cat /etc/X11/default-display-manager) = "/usr/bin/gdm" ] \
   && [ -x /usr/bin/gdm ]; then
  # Sanity checks
  if [ ! -f /etc/gdm/gdm.conf ] ; then
    echo "Missing files: /etc/gdm/gdm.conf" >&2
    exit 1
  fi
  if [ ! -f /etc/gdm/locale.conf ] ; then
    echo "Missing files: /etc/gdm/locale.conf" >&2
    exit 1
  fi
  # Create UTF-8 only locale list
  echo "#
# This is similar to a locale.alias file, but is not one.  This file was
# auto generated from the /etc/gdm/locale.conf by commands in m17n-env
# package which selected only UTF-8 locales.
# Date: $(date -uR || true)" >/etc/gdm/locale-utf-8.conf
  grep -e "UTF-8" /etc/gdm/locale.conf |\
  grep -e '^[ \t]*[^#]' >>/etc/gdm/locale-utf-8.conf
  
  # If 
  if grep -e '^LocaleFile=/etc/gdm/locale.conf$' /etc/gdm/gdm.conf 2>/dev/null >/dev/null ; then
  (
  echo '/^LocaleFile=/s/^.*$/LocaleFile=\/etc\/gdm\/locale-utf-8.conf/'
  echo w
  echo q
  ) | ed -s /etc/gdm/gdm.conf
  elif ! grep -e '^LocaleFile=/etc/gdm/locale-utf-8.conf$' /etc/gdm/gdm.conf 2>/dev/null >/dev/null ; then
  echo "Can not update /etc/gdm/gdm.conf automatically." >&2
  else
  echo "No need to update /etc/gdm/gdm.conf." >&2
  fi
fi

