#!/bin/sh
# Copyright 1993, Patrick Volkerding, Moorhead, MN.
# Use and redistribution covered by the same terms as the "setup" script.
#if [ ! -d /usr/lib/kbd/keytables ]; then
# dialog --title "ɬפʥե뤬Ĥޤ" --msgbox \
#"ǥA3Υѥå'keymaps.tgz'򥤥󥹥ȡ뤹ޤǡ\n\
#ܡѹ뤳ȤϤǤޤ󡣥ѥåˤ\n\
#ʤΤɬפʥܡɥޥåפޤޤƤޤ" 9 70
# exit
#fi

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

dialog --title "ܡѹ" --checklist \
"ܡܸ106/Ѹ101ꡢCaps Lock  CTRL \n\
Ⱦ/ѡץ ESC˳Ƥ򤷤ޤUS 101 \n\
ܡɤȤäƤ䡢촹פʾ X ޡ򳰤\n\
" 14 76 4 \
"106" "ܸ 106 " "$KEYSET106" \
"CTRL" "CTRLCapsLock줫(A κ CTRL ˤʤޤ)" "$SWCTRL" \
"ESC" "Ⱦ/ѡץ ESC (ܸ 106 : ͭ)" "$SWESC" \
    2> /tmp/keys
if [ $? = 1 -o $? = 255 ]; then
  exit
fi

DF="/etc/custom/kbd/defkeymap.map"
JP="/etc/custom/kbd/jp106.map"
CL="/etc/custom/kbd/cl2c-d.map"
K2="/etc/custom/kbd/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 "cl2c-d.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 "cl2c-d.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

