#!/usr/bin/perl
# This script configures fontconfig
use strict;
use warnings;

use IO::File;
use POSIX qw(tmpnam);

# We use postconfig() helper subroutine so we have to include
# its definition
require '/usr/lib/localization-config/common/postconfig.pl';
require '/usr/lib/localization-config/common/log.pl';
require '/usr/lib/localization-config/common/copyfile.pl';

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

# The config filename
my $localconf = '/etc/fonts/local.conf';

# These are X settings -> see /usr/X11R6/lib/locale for charset names
my %lang_map = (
        #entries sorted alphabetically
        'el_GR.UTF-8' => '/usr/lib/localization-config/fontconfig.d/Greek',
             );

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

# check if the locale given is supported
my $conf;
if(defined($lang_map{$lang})) {
    $conf = $lang_map{$lang};
} else {
    log_msg("$0: No support for language $lang");
    exit;
}

copyfile($lang_map{$lang}, $localconf) || log_die("Cannot write $localconf: $!");