#!/bin/sh
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin

TMP=/tmp
if [ ! -d $TMP ]; then
 mkdir -p $TMP
fi

kmap() {
if [ ! -x /etc/rc.d/rc.keymap ]; then
echo "#!/bin/sh
# /etc/rc.d/rc.keymap
#
# This selects your default keymap from among the ones in
# /usr/share/kbd/keymaps.
#
#if [ -x /usr/bin/loadkeys ]; then
#loadkeys uk
#fi
" > /etc/rc.d/rc.keymap
chmod 755 /etc/rc.d/rc.keymap
fi
}

if [ "$1" = "ask" ]; then
dialog --title "CHOOSE KEYBOARD MAP" --yesno "If you don't \
have a US keyboard, select Yes and choose a keymap." 0 0
if [ ! $? = 0 ]; then
if [ ! -f /tmp/skip_tmpfs ]; then
  kmap
fi
  clear
  exit
fi
fi

while [ 0 ]; do
dialog --title "KEYBOARD MAP SELECTION" --menu "You may select one \
of the following keyboard maps. If you do not select a keyboard \
map, (the US keyboard map) is the default. Use the UP/DOWN \
arrow keys to scroll through the whole list of choices." \
20 55 9 \
"azerty" "" \
"be-latin1" "" \
"bg-cp855" "Bulgarian" \
"bg-cp1251" "" \
"bg_bsd-cp1251" "" \
"br-abnt" "Brazilian" \
"br-abnt2" "" \
"br-latin1-abnt2" "" \
"br-latin1-us" "" \
"cf" "French canadian" \
"croat" "" \
"cz-lat2-prog" "Czech" \
"cz-lat2" "" \
"cz-cp1250" "" \
"cz-us-qwertz" "" \
"cz" "" \
"de-latin1-nodeadkeys" "German" \
"de-latin1" "" \
"de" "" \
"de_CH-latin1" "" \
"dk-latin1" "Danish" \
"dk" "" \
"ANSI-dvorak" "" \
"dvorak" "" \
"dvorak-l" "Left-handed" \
"dvorak-r" "Right-handed" \
"es" "Spanish" \
"es-cp850" "" \
"fi-latin1" "Finnish or swedish" \
"fi-latin9" "" \
"fi" "" \
"fr-latin1" "French" \
"fr-latin9" "" \
"fr-pc" "" \
"fr" "" \
"fr_CH-latin1" "" \
"fr_CH" "" \
"gr-pc" "Greek" \
"gr" "" \
"hu" "Hungarian" \
"hu101" "" \
"il-heb" "" \
"is-latin1" "Icelandic" \
"is-latin1-us" "" \
"it-ibm" "Italian" \
"it" "" \
"it2" "" \
"jp106" "Japanese" \
"la-latin1" "Latin american" \
"lt.l4" "Lithuanian" \
"lt.baltic" "" \
"lt" "" \
"no-latin1" "Norway" \
"no" "" \
"nl" "Dutch" \
"nl2" "" \
"pl" "Polish" \
"pl2" "" \
"pt-latin1" "Portuguese" \
"pt-latin9" "" \
"ro_win" "Romanian" \
"ru" "Russian" \
"ru1" "" \
"ru2" "" \
"ru3" "" \
"ru4" "" \
"ru-cp1251" "" \
"ru-ms" "" \
"ru_win" "" \
"se-lat6" "Swedish" \
"sv-latin1" "" \
"sg" "" \
"sg-latin1" "" \
"sk-qwertz" "Slovakian" \
"slovene" "" \
"sr-cy" "Serbian" \
"trf" "Turkish" \
"tr_f-latin5" "" \
"trq" "" \
"uk" "United Kingdom" \
"us" "USA" \
"wangbe" "Belgium" \
"wangbe2" "" \
 2> $TMP/SeTkeymap
 if [ ! $? = 0 ]; then
  rm -f $TMP/SeTkeymap
  exit
 fi

 MAPNAME="`cat $TMP/SeTkeymap`"
 loadkeys $MAPNAME 1> /dev/null 2> /dev/null

 while [ 0 ]; do
  dialog --title "KEYBOARD TEST" --inputbox \
  "OK, the new map is now installed. You may now test it by typing \
  anything you want. To quit testing the keyboard, enter 1 on a \
  line by itself to accept the map and go on, or 2 on a line by \
  itself to reject the current keyboard map and select a new one." \
  11 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
echo "#!/bin/sh
# /etc/rc.d/rc.keymap
#
# This selects your default keymap from among the ones in
# /usr/share/kbd/keymaps.
#
if [ -x /usr/bin/loadkeys ]; then
  loadkeys $MAPNAME
fi
" > /etc/rc.d/rc.keymap
 chmod 755 /etc/rc.d/rc.keymap
 clear
 break;
 else
  rm -f $TMP/SeTkeymap
  loadkeys us 1> /dev/null 2> /dev/null
  if [ ! -f /tmp/skip_tmpfs ]; then
    kmap
  fi
  continue;
 fi
done
