# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: 

inherit eutils

DESCRIPTION="DarkLin Release"
SLOT="0"
LICENSE="GPL-2"
KEYWORDS="amd64 x86"
DARKLIN_DISTRIB="Charon"
DEPEND="dev-lang/perl"

src_install() {
    dodir /etc/

    echo ${PV} > ${D}/etc/darklin-version
    echo "DarkLin IV ($DARKLIN_DISTRIB)" > ${D}/etc/darklin-release
    
    cat "${FILESDIR}"/issue | sed -e "s/@name@/$DARKLIN_DISTRIB/g" -e "s/@version@/$PV/g" > ${D}/etc/issue
}

pkg_postinst() {
perl -s -e '$^I="";
if (@argv == 2) { $PN=pop(@argv); }
$NOT_STARTED=1;$COMMENTS=1;$BL="";
while (<>)
{
    $value=$_;
    
    if ($value=~m/^\s*loginsh=/) {
	next;
    }

    if (($COMMENTS)&&($value!~m/^\s*#/)) {
	print "loginsh=1\n";
	$COMMENTS=0;
    } 
    
    if ((defined $PN)&&($value=~m/CfgStart\s*$PN/)) {
	$NOT_STARTED=0;
    } elsif ((defined $PN)&&($value=~m/CfgEnd\s*$PN/)) {
	$NOT_STARTED=1;
    } elsif ($NOT_STARTED) {
	if ($value =~ m/^\s*$/) {
	    $BLS.=$value;
	} else {
	    print $BLS;
	    print $value;
	    $BLS=""
	}
    }
}
if ($value !~ m/$\s*^/) {
    print "\n";
}' -- -PN=darklin  /etc/profile 

perl -s -e '$^I="";
if (@argv == 2) { $PN=pop(@argv); }
$NOT_STARTED=1;$COMMENTS=1;$BL="";
while (<>)
{
    $value=$_;
    
    if ((defined $PN)&&($value=~m/CfgStart\s*$PN/)) {
	$NOT_STARTED=0;
    } elsif ((defined $PN)&&($value=~m/CfgEnd\s*$PN/)) {
	$NOT_STARTED=1;
    } elsif ($NOT_STARTED) {
	if ($value =~ m/^\s*$/) {
	    $BLS.=$value;
	} else {
	    print $BLS;
	    print $value;
	    $BLS=""
	}
    }
}
if ($value !~ m/$\s*^/) {
    print "\n";
}' -- -PN=darklin  /etc/bash/bashrc

    cat "${FILESDIR}"/bashrc >> /etc/bash/bashrc
    cat "${FILESDIR}"/profile >> /etc/profile
}