#!/bin/sh

# Include gnome-shell's custom built schemas in XDG_DATA_DIRS,
# which allows the new settings to show up in dconf-editor:
SYS_DATADIR=/usr/share
ALT_DATADIR=$SYS_DATADIR/gnome-shell/gsettings-desktop-schemas
if [ -e "$ALT_DATADIR" ]; then
  export XDG_DATA_DIRS=$ALT_DATADIR:$SYS_DATADIR:$XDG_DATA_DIRS
fi

if [ "x$XDG_SESSION_TYPE" = "xwayland" ] &&
   [ "x$XDG_SESSION_CLASS" != "xgreeter" ] &&
   [  -n "$SHELL" ] &&
   grep -q "$SHELL" /etc/shells &&
   ! (echo "$SHELL" | grep -q "false") &&
   ! (echo "$SHELL" | grep -q "nologin"); then
  if [ "$1" != '-l' ]; then
    exec bash -c "exec -l '$SHELL' -c '$0 -l $*'"
  else
    shift
  fi
fi

# Force blocaled to update LANG according to /etc/profile.d/lang.sh:
if [ -f /etc/profile.d/lang.sh ]; then
  (
  source /etc/profile.d/lang.sh
  busctl call org.freedesktop.locale1 /org/freedesktop/locale1 org.freedesktop.locale1 SetLocale "asb" 1 "LANG=$LANG" 0
  )
  # If we are GDM then source /etc/profile.d/lang.sh for real:
  [ "x$XDG_SESSION_CLASS" = "xgreeter" ] && source /etc/profile.d/lang.sh
fi

SETTING=$(G_MESSAGES_DEBUG='' gsettings get org.gnome.system.locale region)
REGION=${SETTING#\'}
REGION=${REGION%\'}

if [ -n "$REGION" ]; then
  unset LC_TIME LC_NUMERIC LC_MONETARY LC_MEASUREMENT LC_PAPER

  if [ "$LANG" != "$REGION" ] ; then
    export LC_TIME=$REGION
    export LC_NUMERIC=$REGION
    export LC_MONETARY=$REGION
    export LC_MEASUREMENT=$REGION
    export LC_PAPER=$REGION
  fi
fi

exec /usr/libexec/gnome-session-binary "$@"
