#! /bin/sh -
#
# Script to create a list of menu items for the keyboard selection.
# This is specific for SYSLINUX/ISOLINUX.
#

set -e

# Default values

location=/usr/share/keymaps/i386
output=keys_i386.cfg

echo ""
echo "Looking for keymaps at $location ..."
echo ""

# Compose header for 'output' file

cat << EOF > $output
MENU BEGIN keymap
    MENU TITLE Keyboard map

EOF

# Search of keymaps

find $location \( ! -path '*fgGIod*' -a ! -path '*include*' \) | sort | \
 while read -r line
 do
     test -f "$line" || continue;

     category="${line%/*}"
     category="${category##*/}"		# Extract up the last level.
     file="${line##*/}"			# Full file name.
     file="${file%.map*}"		# Get the rid of file extension.

     # Add body content to 'output' file

     # Make default entry, help text
     if test "${category}/$file" = qwerty/us
     then
         cat << EOF >> $output
    LABEL ${category}/$file
        MENU LABEL ^${category}/$file
        MENU DEFAULT
        COM32 cmd.c32
        APPEND dragora RC_KEYMAP=${category}/$file
        TEXT HELP
    This menu is organized as keyboard "Layout/Language".
    Select a keyboard map for the console before booting:
    ${category}/$file [default]
        ENDTEXT

EOF
     continue;
     fi

cat << EOF >> $output
    LABEL ${category}/$file
        MENU LABEL ${category}/$file
        COM32 cmd.c32
        APPEND dragora RC_KEYMAP=${category}/$file
        TEXT HELP
    This menu is organized as keyboard "Layout/Language".
    Select a keyboard map for the console before booting:
    ${category}/$file
        ENDTEXT
EOF
 done

# Compose footer for 'output' file

cat << EOF >> $output
    MENU SEPARATOR

    LABEL return
        MENU LABEL ^Return to main menu
        MENU EXIT
MENU END
EOF

echo "Output file: $output"
echo ""

