#!/bin/bash

set -e

if [ -e /tmp/tmp.gconf ]; then
   rm -rf /tmp/tmp.gconf
fi

if [ `cp -Rf ~/.gconf /tmp/tmp.gconf` ]; then
   exit 1
fi

chmod -R 755 /tmp/tmp.gconf

tmplayout=`gconftool-2 --get /apps/gdm/simple-greeter/recent-layouts|awk -F"," '{print $1}'`
echo $tmplayout > /tmp/xkb_layout

tmpvar=`xfconf-query -c keyboard-layout -p /Default/XkbVariant|awk -F"," '{print $1}'`
echo $tmpvar > /tmp/xkb_variant

tmpdisable=`xfconf-query -c keyboard-layout -p /Default/XkbDisable`
if [ "true" = $tmpdisable ];then
echo 1 > /tmp/xkb_disable
else
echo 0 > /tmp/xkb_disable
fi

#clean cache file to ensure xkb layout seting consistence
rm /var/cache/gdm/$USER/dmrc
rm ~/.dmrc

exit 0
