#!/bin/sh

PATH=/bin:/usr/bin
SYSFONTDIR=/etc/sysconfig/console/consolefonts
SYSTRANSDIR=/etc/sysconfig/console/consoletrans
I18NFILE=/etc/sysconfig/i18n

_fpath()
{
    if [ -f $1/$2.$3.gz ]; then
	echo -n "$1/$2.$3.gz"
    elif [ -f $1/$2.$3 ]; then
	echo -n "$1/$2.$3"
    else
	echo "$2"
    fi
}

case $1 in
    '') : # Don't do anything, just proceed.
        ;;
    *)

        DOCDIR=$(ls -d /usr/share/doc/initscripts-*)
        cat << EOF

Error: $0 doesn't take any arguments. It is a part of the system
initscripts. It reads $I18NFILE to set the font in the
console.

Read $DOCDIR/sysconfig.txt for detailed documentation of
$I18NFILE

EOF
        exit 1 ;;
esac

if [ -f $I18NFILE ]; then
    . $I18NFILE
fi

case "$LANG" in
    *.utf8|*.UTF-8)
      	 exec unicode_start $SYSFONT $SYSFONTACM
	 ;;
esac

if [ -x /bin/consolechars -o -x /usr/bin/consolechars ]; then
    if [ -n "$SYSFONT" ]; then
    	    ARGS="-f $(_fpath $SYSFONTDIR $SYSFONT psf)"
        if [ -n "$UNIMAP" ]; then
	    ARGS="$ARGS --sfm $(_fpath $SYSTRANSDIR $UNIMAP sfm)"
        fi
        if [ -n "$SYSFONTACM" ]; then
	    ARGS="$ARGS --acm $(_fpath $SYSTRANSDIR $SYSFONTACM acm)"
        fi
        consolechars $ARGS
    fi
elif [ -x /bin/setfont ]; then
  if [ -n "$UNIMAP" ]; then
    ARGS="-u $UNIMAP"
  fi
  if [ -n "$SYSFONTACM" ]; then
    ARGS="$ARGS -m $SYSFONTACM"
  fi
  if [ -n "$SYSFONT" ]; then
    /bin/setfont $SYSFONT $ARGS
#  else
#    /bin/setfont
    echo -ne "\033(K" > /dev/console
  fi
else
  echo $"can't set font"
  exit 1
fi

exit 0
