#!/bin/bash

main(){
  local wm=xfce4-session
  local wm_prog=.xprograms
  local xkeymap=

  if [[ -f /etc/keymap ]] ; then
    xkeymap=$(fss_basic_read -c 0 -n keymap /etc/keymap)

    if [[ $xkeymap != "" ]] ; then
      setxkbmap $xkeymap
    fi
  fi

  if [[ $WM != "" ]] ; then
    wm=$WM
  fi

  if [[ $WM_PROG != "" ]] ; then
    wm_prog=$WM_PROG
  fi

  if [[ $wm == "xfce4-session" ]] ; then
    export DESKTOP_SESSION="xfce"
  fi

  if [ -e ~/$wm_prog ] ; then bash ~/$wm_prog ; fi

  if [[ $(type -p dbus-launch) != "" ]] ; then
    exec dbus-launch --sh-syntax --exit-with-session $wm
  else
    exec $wm
  fi
}

main
