# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# app-i18n/ucw-cs

inherit eutils toolchain-funcs

DESCRIPTION="Alternative support for Czech Linux console"
HOMEPAGE="http://atrey.karlin.mff.cuni.cz/~mj/linuxcs/"
SRC_URI="ftp://atrey.karlin.mff.cuni.cz/pub/local/mj/linux/ucw-cs-1.1.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="x86"

RDEPEND="sys-apps/kbd"
DEPEND="${RDEPEND}"

src_unpack() {
	unpack ${P}.tar.gz
	EPATCH_OPTS="-d ${S}"
	epatch ${FILESDIR}/moreconsoles.patch
}

src_install() {
	dodoc ChangeLog README index.html

	dodir /usr/share/keymaps/i386/ucw-cs
	insinto /usr/share/keymaps/i386/ucw-cs
	doins keymaps/*
	insinto /usr/share/consolefonts
	doins fonts/*.psf
}

pkg_postinst() {
	einfo "To setup ucw-cs to run out-of-the-box on your system, run:"
	einfo "ebuild /var/db/pkg/${CATEGORY}/${PF}/${PF}.ebuild config"
	echo
	einfo "Otherwise, you need to manually edit those files:"
	einfo '/etc/conf.d/consolefont: CONSOLEFONT="ucw16"'
	einfo '                         CONSOLETRANSLATION="8859-2_to_uni"'
	einfo '/etc/conf.d/keymaps:     KEYMAP="cs-head cs-compose cs-ucw"'
	echo
	einfo "Obviously, you may configure your system to use different ucw-cs"
	einfo "fonts and/or keymaps. Refer to ucw-cs documentation for the list"
	einfo "of available fonts and keymap guide."
	echo
	ewarn "ucw-cs was not tested with Unicode console"
}

pkg_config() {
	# _Everyone_ has perl. Right? Right.
	ebegin "Setting up the ucw16 font"
	perl -i -pe 's/^CONSOLEFONT=/#$&/;
	             s/^CONSOLETRANSLATION=/#$&/' /etc/conf.d/consolefont
	cat <<_E_ >>/etc/conf.d/consolefont

# ucw-cs:
CONSOLEFONT="ucw16"
CONSOLETRANSLATION="8859-2_to_uni"
_E_
	eend $?

	ebegin "Setting up the cs-ucw keymap"
	perl -i -pe 's/^KEYMAP=/#$&/' /etc/conf.d/keymaps
	cat <<_E_ >>/etc/conf.d/keymaps

# ucw-cs:
KEYMAP="cs-head cs-compose cs-ucw"
_E_
	eend $?
}
