#!/bin/sh
# Copyright 1993, Patrick Volkerding, Moorhead, MN.
# Use and redistribution covered by the same terms as the "setup" script.


expand_mes () {
    source /usr/lib/setup/SeTkeymap.mes
}

KEYSET106=off
SWCTRL=off
SWESC=off
if [ -f /tmp/keyset ] ; then
  if [ ! "`grep jp106 /tmp/keyset`" = "" ] ; then 
    KEYSET106=on
    SWESC=on
  fi
  if [ ! "`grep cl2c-d /tmp/keyset`" = "" ] ; then 
    SWCTRL=on
  fi 
  if [ ! "`grep k2esc-d /tmp/keyset`" = "" ] ; then 
    SWESC=on
  fi
fi

expand_mes
dialog --title "Change KBD configuration" --checklist "$kbd_mes" 14 76 4 \
"106" "$list_01" "$KEYSET106" \
"CTRL" "$list_02" "$SWCTRL" \
"ESC" "$list_03" "$SWESC" \
    2> /tmp/keys
if [ $? = 1 -o $? = 255 ]; then
  exit
fi

DF="defkeymap.map"
JP="jp106.map"
CL="ctrl.map"
K2="k2esc-d.map"

if grep 106 /tmp/keys 1> /dev/null 2> /dev/null ; then
	echo "jp106.map" > /tmp/keyset
	if grep CTRL /tmp/keys 1> /dev/null 2> /dev/null ; then
		echo "ctrl.map" >> /tmp/keyset
		loadkeys $JP $CL
	else
		loadkeys $JP
	fi
else
	echo "defkeymap.map" > /tmp/keyset
	if grep CTRL /tmp/keys 1> /dev/null 2> /dev/null ; then
		echo "ctrl.map" >> /tmp/keyset
		if grep ESC /tmp/keys 1> /dev/null 2> /dev/null ; then
        		echo "k2esc-d.map" >> /tmp/keyset
			loadkeys $DF $CL $K2
		else
			loadkeys $DF $CL
		fi
	else
		if grep ESC /tmp/keys 1> /dev/null 2> /dev/null ; then
        		echo "k2esc-d.map" >> /tmp/keyset
			loadkeys $DF $K2
		else
			loadkeys $DF
		fi
	fi
fi
