#!/usr/bin/perl
# Example postinst wrapper script to configure a package.
# This calls the appropriate script according to the version map.
# This is an example, modify it according to your needs.

use strict;
use warnings;
use Getopt::Std;

use vars qw(%opts $LIB $debug $package $lang %xvermap $release);

# We use methods in common.pl
require '/usr/lib/localization-config/common/common.pl';

# The path where the scripts are kept
$LIB = '/usr/lib/localization-config';

# call init() to initialize the APT config system
init();

# Define the version map for the package
# For now we only add the minimum versions for woody and sarge.
# Specifically, the version map defines the *minimum* versions
# for which the package changes the way it is configured.
# The method is quite generic, more releases can be added on demand.
# 
# If the package does not change its configuration system, then you
# can do one of two things:
#  a) Leave just one entry in the version map (the minimum possible)
#  b) Leave all entries in the version and make the latter ones links
#     to the first one (relative links, please)
#
# If a package does not exist, for example in woody, then use just one
# release entry and write it's sarge version in the version map.
#
# If you don't want a package to be configured anymore (for example it
# needed configuration in woody but not in sarge) then you can create its
# version map normally as if it was to be configured in the first place.
# Then make the configuration script (sarge/package in this case) a dummy one.
# 
my %vermap = ( '#MINIMUM_WOODY_VERSION#',     => { RELEASE => 'woody' },
               '#MINIMUM_SARGE_VERSION#',     => { RELEASE => 'sarge' }
              );

# Get locale entry
$lang = shift;

# Which script to execute
my $script = "#SCRIPT#"; 
# Which package to search
my $package = "#PACKAGE#";

# This is a preinst script, we don't need the package to be installed.

# Get appropriate release for this package
my $release = get_release($package, %vermap);

# Execute the corresponding script
$script = "$LIB/$release/".$script;
print "Running $script $lang\n";
system ($script, $lang) if -x $script;

1;
