#!/usr/bin/perl
# This script configures XFree86 for LTSP in skolelinux.

use strict;
use warnings;

require '/usr/lib/localization-config/sarge/lang_X_map.pl';
require '/usr/lib/localization-config/common/xfree86-kbd.pl';
require '/usr/lib/localization-config/common/editconfig.pl';
require '/usr/lib/localization-config/common/log.pl';

BEGIN {
    my @f = split(m%/%, $0); pop @f;
    push @INC, join("/", @f);
}

# If no locale is given as argument, quit
my $lang = $ARGV[0] or log_die("$0: No language given");

my $LTS_CONF = "/opt/ltsp/i386/etc/lts.conf";

my %keynames = get_keynames();
my %lang_locale_map = get_lang_map();
my %lang_console_map = get_lang_console_map();
my %lang_X_map = get_lang_X_map();
my %subarch_map = get_subarch_map();

# Print the supported locale entries.
if ("supported" eq $lang) {
    for $lang (sort keys %lang_locale_map) {
        print "$lang\n";
    }
    exit 0;
}

if ( ! -f $LTS_CONF ) {
    log_msg("$0: warning: ltsp-xfree86-kbd: Doing nothing, $LTS_CONF is missing.");
    exit 0;
}

my $section = "Default";
my %sel = select_Xkb($lang, \%lang_X_map, \%lang_console_map, \%keynames);
for my $key (sort keys %sel) {
    log_msg("$0: Selected: ".$key.":\t".$sel{$key});
    UpdateOrAppendVariable($LTS_CONF, $key, $sel{$key}, "=", $section, "\t");
}

1;