#!/bin/sh
# This script works just like "loadkeys" but automatically uncompresses
# gzipped map files.  The files are expected to be in /usr/lib/kbd/keytables.

# First, find the apparent map name.  This should be the last argument given.
for map in $* ; do
 ARGS="$ARGS $OLD" # OK, this adds the arg found the last time we looped
 OLD=$MAP
 MAP=$map
done

# If the file asked for ends with .gz, lets strip it.
MAP=`basename $MAP .gz`

# Then, if it's got a .map suffix, we strip that too.
MAP=`basename $MAP .map`

# Now, let's load that map:
if [ -r /usr/lib/kbd/keytables/$MAP.map ]; then
  loadkeys /usr/lib/kbd/keytables/$MAP.map
elif [ -r /usr/lib/kbd/keytables/$MAP.map.gz ]; then
  gzip -d /usr/lib/kbd/keytables/$MAP.map.gz
  loadkeys /usr/lib/kbd/keytables/$MAP.map
  gzip -9 /usr/lib/kbd/keytables/$MAP.map
elif [ -r /usr/lib/kbd/keytables/`echo $MAP.map.gz | cut -b-14` ]; then
  NAME=`echo $MAP | cut -f 1 -d '.'`.map
  NAME=`echo $NAME | cut -b-14` # This usually happens on MINIX fs, so...
  zcat /usr/lib/kbd/keytables/`echo $MAP.map.gz | cut -b-14` > /tmp/$NAME
  loadkeys /tmp/$NAME
  rm /tmp/$NAME
fi
