#!/bin/sh
# Copyright 1993, 1999 Patrick Volkerding, Moorhead, MN.
# Use and redistribution covered by the same terms as the "setup" script.
#
# Modified by Eko M. Budi for Vector Linux Install
# - Write /tmp/setup.keymap to be picked up by the next configuator
# - Tidy up the display 
# - synchronize with the available keymap in the initrd

BACKTITLE="Vector Linux Keymap"

vdir=$(dirname $0)
. $vdir/setup-functions

TMP=/var/log/setup/tmp
if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi
RDIR=/dev/tty7

while [ 0 ]; do
dialog --backtitle "$BACKTITLE" --title "KEYBOARD MAP SELECTION" --menu "\n
You may select one of the following keyboard maps. If you do not
select a keyboard map, 'us.map' is the default." 20 55 9 \
us.bmap "USA/Canadian"  \
be.bmap "Belgian" \
br.bmap "Brazilian" \
cf.bmap "French Canadian" \
de.bmap "German" \
dk.bmap "Danish" \
es.bmap "Espanol" \
fi.bmap "Finnish/Swedish" \
fr.bmap "French" \
gr.bmap "Greek" \
hu.bmap "Hungarian" \
it.bmap "Italian" \
jp.bmap "Japanese" \
no.bmap "Norway" \
pl.bmap "Poland" \
ru.bmap "Russian" \
se.bmap "Swedish" \
uk.bmap "United Kingdom" \
2> $TMP/SeTkeymap
 if [ ! $? = 0 ]; then
  rm -f $TMP/SeTkeymap
  exit
 fi

 MAPNAME="`cat $TMP/SeTkeymap`"

 gzip -dc /usr/share/keymaps/${MAPNAME}.gz | loadkmap 1> $RDIR 2> $RDIR
 
 dbug "Keymap ${MAPNAME} loaded"
 
 while [ 0 ]; do
  dialog --backtitle "$BACKTITLE" --title "KEYBOARD TEST" --inputbox "\n
OK, the new map has been loaded. You may now test it by typing 
anything you want, especially the unique keys of your map.\n
  - Enter '1' on a line by itself to accept the map and go on.\n
  - Enter '2' to reject the current map and select a new one.\n
Please type some keys then press [Enter]:" \
13 70 2> $TMP/keytest
  if [ $? = 1 ]; then
   REPLY="n"
   break;
  fi
  REPLY="`cat $TMP/keytest`"
  rm -f $TMP/keytest
  if [ "$REPLY" = "1" -o "$REPLY" = "2" ]; then
   break;
  fi
 done
 if [ "$REPLY" = "1" ]; then
  break;
 else
  rm -f $TMP/SeTkeymap
  gzip -dc /usr/share/keymaps/us.bmap.gz | loadkmap 1> $RDIR 2> $RDIR
 continue;
 fi
done

#### Pass the map name
echo "${MAPNAME%*.map}" > $SETUP_KEYMAP

