#!/bin/sh -e

PROG="${0##*/}" #program name

fonts_file=/usr/share/predator/consolefonts
font_config=/etc/sysconfig/consolefont

. /etc/sysconfig/i18n

print_version()
{
	cat <<EOF
$PROG version 0.0.1

Written by Stanislav Ievlev

Copyright (C) 2004 ALT Linux Team
EOF
	exit
}

print_usage()
{
	[ "$1" = 0 ] || exec >&2
	cat <<EOF
Usage: $PROG [options]

utility to setup console font according current i18n system settings

Valid options are:
  -h, --help	display help screen
  -v, --version	display version information

Report bugs to <inger@altlinux.org>
EOF
	[ -n "$1" ] && exit "$1" || exit
}


TEMP=`getopt -n $PROG -o h,v -l help,version -- "$@"` || print_usage
eval set -- "$TEMP"

while :; do
	case "$1" in
		-h|--help) print_usage 0
			;;
		-v|--version) print_version
			;;
		--) shift; break
			;;
		*) Fatal "unrecognized option: $1"
			;;
	esac
	shift
done


charmap=$(LC_ALL=$LANG locale charmap)

font=$(cat $fonts_file|grep "^$charmap"|cut -f2)
unimap=$(cat $fonts_file|grep "^$charmap"|cut -f3)
acm=$(cat $fonts_file|grep "^$charmap"|cut -f4)

echo "font=$font"
echo "unimap=$unimap"
echo "acm=$acm"

>$font_config
[ "$font" == "undef" ] || echo "SYSFONT=$font">>$font_config
[ "$unimap" == "undef" ] || echo "UNIMAP=$unimap">>$font_config
[ "$acm" == "undef" ] || echo "SYSFONTACM=$acm">>$font_config
