#!/bin/sh
#
# Tazkmap - SliTaz GNU/Linux BusyBox keymap config using dialog boxes.
# Configuration file is : /etc/kmap.conf
# 
# 20080412 <pankso@slitaz.org> - GNU gpl.
#
: ${DIALOG=dialog}

# Script functions.
status()
{
	local CHECK=$?
	echo -en "\\033[70G[ "
	if [ $CHECK = 0 ]; then
		echo -en "\\033[1;33mOK"
	else
		echo -en "\\033[1;31mFailed"
	fi
	echo -e "\\033[0;39m ]"
}

# Check if user is root.
#
if test $(id -u) != 0; then
  echo ""
  echo "You must be root to run `basename $0`!"
  echo "Type 'su' and root password to become super-user."
  echo ""
  exit 1
fi

# Dialog menu.
#
exec 3>&1
value=`$DIALOG  --clear \
    --title " SliTaz kmap configuration " \
    --menu \
"Slctionnez votre clavier - Select your keymap." 15 70 5 \
"fr_CH" "Suisse franais." \
"fr" "Franais" \
"be" "Belge" \
"ca" "Canadian" \
"cz" "Czech" \
"de" "Deutch" \
"en" "English UK" \
"es" "Spanish" \
"it" "Italiano" \
"jp" "Japanese" \
"us" "USA" \
2>&1 1>&3`
retval=$?
exec 3>&-

case $retval in
  0)
    echo -n "$value selected... "
    status ;;
  1)
    echo "Cancel pressed."
    exit 0 ;;
  255)
    if test -n "$value" ; then
      echo "$value"
    else
      echo "ESC pressed."
      exit 0
    fi ;;
esac

# Export selected value.
#
echo -n "Exporting $value to $value.kmap..."
export KMAP=$value.kmap
status

# Now we can load the selected kmap file from /usr.
#
echo -n "Creating config file : /etc/kmap.conf"
echo "KMAP=$KMAP" > /etc/kmap.conf
status

echo -n "Loading keymap : $KMAP..."
/sbin/loadkmap < /usr/share/kmap/$KMAP
status

exit 0
