#!/usr/bin/perl -w

#----------------------------------------------------------------------
# copyright (C) 2002 Mitel Networks Corp.
#		
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#		
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.
#		
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
#----------------------------------------------------------------------

package esmith;

use strict;
use Errno;
use esmith::ConfigDB;

open F, "/etc/sysconfig/i18n";
my ($line) = grep(/^LANG/, <F>);
close F;

my $lang;
if($line =~ /^LANG="(.*)"/) 
{
	$lang = $1;
}
else
{
	$lang = "en-us";
}

open F, "/etc/sysconfig/keyboard";
my @lines = <F>;
close F;

my ($kbdtype) = grep(/^KEYBOARDTYPE/, @lines);
if($kbdtype =~ /^KEYBOARDTYPE="(.*)"/)
{
	$kbdtype = $1;
} 
else
{
	$kbdtype = "pc";
}

my ($keytable) = grep(/^KEYTABLE/, @lines);
if($keytable =~ /^KEYTABLE="(.*)"/)
{
	$keytable = $1;
}
else
{
	$keytable = "us";
}

my $conf = esmith::ConfigDB->open() or die "Unable to open config DB";
my $rec = $conf->get('sysconfig');
if ($rec)
{
	$rec->set_prop('Language', $lang);
	$rec->set_prop('KeyboardType', $kbdtype);
	$rec->set_prop('Keytable', $keytable);
}
else
{
	$rec = $conf->new_record('sysconfig', {
		type => 'configuration', 
		Language => $lang,
		KeyboardType => $kbdtype,
		Keytable => $keytable,
		});
}

exit 0;

