#! /bin/sh -e

VERSION="set-m17n-env (Version: 0.0.4)"
USAGE="set-m17-env [option]
Option:
  -x    Skip updating locale
  -v    Display version
  -h    Display help
"

ZAPCOMMAND=":"
UPDATE_LOCALE="yes"
while getopts hvzx f
  do
    case $f in
    v)  echo $VERSION; exit 0;;
    x)  UPDATE_LOCALE="no";;
    h)  echo $USAGE; exit 0;;
    \?)     echo $USAGE; exit 1;;
     esac
done
shift `expr $OPTIND - 1`

# When run from root
if [ $UID = 0 ]; then
# update menu
# set up utf-8 locales
  if [ $UPDATE_LOCALE = "yes" ]; then
    . /usr/share/m17n-env/bin/set-utf-8
    echo "UTF-8 locales verified/updated"
  fi
  . /usr/share/m17n-env/bin/set-menu
  echo "Menu set, rebuilding menu ..."
  LANG=C LC_ALL=C update-menus
  echo "Menu updated"
# gdm->utf-8 only
  . /usr/share/m17n-env/bin/set-gdm-utf-8
  echo "GDM updated"
  exit
fi

# When run from non-root
. /usr/share/m17n-env/bin/set-dmrc
echo "DM updated"

. /usr/share/m17n-env/bin/set-xresources
echo "~/.Xresources updated"
echo "*** If you are running under X, ***"
echo "*** please restart X by logging out from the X session. ***"

