2
# -------------------------------------------------------------------------------
3
# dictionaries-common.config-base:
4
# dc-debconf-select.pl will be added to the end of this file
5
# to make dictionaries-common.config
6
# -------------------------------------------------------------------------------
8
use Debconf::Client::ConfModule q(:all);
12
if ( -l "/etc/dictionary" ) {
13
input ("medium","dictionaries-common/old_wordlist_link");
16
if ( not -l "/usr/dict" ){
17
set("dictionaries-common/remove_old_usr_dict_link","false");
22
# Trying to find a reasonable guess for default ispell dictionary and wordlist
23
# from the debian-installer settings, envvars or pre-policy symlinks and the
24
# list of ispell dictionaries and wordlists to be installed
26
$priority{"ispell"} = "critical";
27
$priority{"wordlist"} = "critical";
28
$di_language = "debian-installer/language";
29
$di_country = "debian-installer/country";
30
$dcscript = "/usr/share/dictionaries-common/dc-debconf-select.pl";
31
$fromdcconfig = "yes";
32
$debug = "yes" if exists $ENV{'DICT_COMMON_DEBUG'};
35
my %debconf_vals = ();
36
my @suffixes = ("","-large","-medium","-small","-gut");
37
my %equivs = ("bg" => "bulgarian",
44
"en_US" => "american",
45
"en_US:1" => "miscfiles",
46
"en_CA" => "canadian",
47
"en_CA:1" => "american",
57
"gl" => "galician-minimos",
62
"nb" => "norwegian->bokmal",
64
"nn" => "norwegian->nynorsk",
67
"pt_BR" => "brazilian",
72
my %pending_keys = ();
73
my %reverse_equivs = ();
74
my %alternatives = ("ispell" => "ispell-dictionary.hash",
75
"wordlist" => "dictionary");
77
# -------------------------------------------------------------
79
# -------------------------------------------------------------
80
# Show info if in debug mode
81
# -------------------------------------------------------------
82
print STDERR "@_" if $debug;
85
# -------------------------------------------------------------
87
# -------------------------------------------------------------
88
# Set debconf value unless already set
89
# -------------------------------------------------------------
92
my $priority = $priority{$class} || "";
94
my ($errorcode, $oldvalue) = get($question);
96
$oldvalue = "unset" unless $oldvalue;
98
if ( $errorcode or $oldvalue eq "unset" ){
99
&dc_debugprint(" $question: errorcode: $errorcode; priority: $priority\n" .
100
" Old:[$oldvalue] --> New:[$value]\n");
101
set("$question","$value");
102
} elsif ( $oldvalue eq $value ) {
103
print STDERR "Info: $question is already set to
104
[$oldvalue]. Preserving it.\n";
106
print STDERR "Warning: $question is already set to
108
Not setting to [$value]\n";
111
if ( $debug ){ # --- Check if question value is actually set
112
($errorcode, $oldvalue) = get($question);
114
print STDERR "dictionaries-common: $question reading failed with $errorcode\n";
115
} elsif ( $oldvalue) {
116
print STDERR "dictionaries-common: $question actually set to [$oldvalue]\n";
118
print STDERR "dictionaries-common: $question value is void, bad thing\n";
121
&dc_debugprint ("Not tried: " . join(', ',sort keys %pending_keys) . "\n---\n");
124
# -------------------------------------------------------------
125
sub extractlangname (){
126
# -------------------------------------------------------------
127
# Look if a dict matching $langkey in %equivs is to be installed
128
# and return the preferred language name if so.
129
# -------------------------------------------------------------
136
if ( exists $pending_keys{$langkey} ){ # Make sure we do not try it again
137
&dc_debugprint("Trying langkey $langkey\n");
138
delete $pending_keys{$langkey};
140
if ( exists $equivs{$langkey} ){
141
# This $langkey was already tried, no need to try it again
142
&dc_debugprint("Already done langkey $langkey\n");
144
# This $langkey does not exist
145
&dc_debugprint("Non-existant langkey $langkey\n");
150
if ( exists $equivs{$langkey} ){
151
($thepackage,$thevariant) = split ("->",$equivs{$langkey});
152
foreach $suffix ( @suffixes ){
153
if ( $thepackage eq "miscfiles" ){
154
$pkgfullname = "$thepackage$suffix";
156
$pkgfullname = "$classprefix$thepackage$suffix";
158
&dc_debugprint(" Trying package $pkgfullname\n");
159
if ( exists $debconf_vals{"$pkgfullname"} ){
160
if ( exists $debconf_defaultvals{"$pkgfullname"} ){
161
$thestring = $debconf_defaultvals{"$pkgfullname"};
163
$thestring = $debconf_vals{"$pkgfullname"};
165
@thevalues = sort split (/\s*,\s*/,$thestring);
167
@thevalues = grep {/$thevariant/i} @thevalues;
170
$a =~ m/tex/i <=> $b =~ m/tex/i # Sort tex variants last
172
$a cmp $b } @thevalues;
173
if ( scalar @thevalues >= 1 ){
174
return "$thevalues[0]";
183
# -------------------------------------------------------------
185
# -------------------------------------------------------------
186
# Try different combinations of $language and $country and possible
187
# fallbacks in case extractlangname() does not find a good guess
188
# -------------------------------------------------------------
190
my $language = shift;
193
my @possible_fallbacks = ();
195
if ( $guessed = &extractlangname("$language" . "_" . uc($country))
196
|| &extractlangname("$language" . "_" . uc("$country") . ":1")
197
|| &extractlangname("$language")
198
|| &extractlangname("$language:1")
200
$priority{$class} = "low";
203
@possible_fallbacks = grep {/$language\_/} sort keys %equivs;
204
$priority{$class} = "medium";
205
foreach ( @possible_fallbacks ){
206
return $guessed if ( $guessed = &extractlangname($_));
208
$priority{$class} = "high";
213
# -------------------------------------------------------------
214
sub guessotherlang (){
215
# -------------------------------------------------------------
216
# Iterate over the not yet tried $langkey values for a dict to be
217
# installed. Return first match
218
# -------------------------------------------------------------
221
foreach ( sort keys %pending_keys ){
222
return $guessed if ( $guessed = &extractlangname($_));
226
# -------------------------------------------------------------
227
sub guesslang4link(){
228
# -------------------------------------------------------------
229
# Try guessing default value after (woody or older) former symlink
230
# -------------------------------------------------------------
235
my $link = "/etc/alternatives/$alternatives{$class}";
237
return if not ( -l $link );
239
if ( $guess = readlink($link) ){
241
&dc_debugprint("Found link $guess. ");
243
$guess =~ s/\.hash$//;
245
$guess =~ s/(\-\.)(small|medium|large)$//;
246
$guess =~ s/\-english$//;
248
$guess = "norwegian->bokmal" if ($guess eq "bokm�l");
249
$guess = "norwegian->nynorsk" if ($guess eq "nynorsk");
250
$guess = "ogerman" if ($guess eq "german");
251
$guess = "miscfiles" if ($guess eq "web2");
252
$guess = "danish" if ($guess eq "dansk");
253
$guess = "french" if ($guess eq "francais");
254
$guess = "swedish" if ($guess eq "svenska");
256
&dc_debugprint("Fine tuned to $guess.\n");
258
if ( exists $reverse_equivs{$guess} ){
259
$language = $reverse_equivs{$guess};
263
return $guessed if ( $guessed = &extractlangname($language) );
268
# -------------------------------------------------------------
269
sub dc_manual_alternative (){
270
# -------------------------------------------------------------
271
# Check if woody (or older) alternative exists and is set to manual
272
# -------------------------------------------------------------
274
my $file = "/var/lib/dpkg/alternatives/$alternatives{$class}";
278
open(FILE,"< $file") or return;
281
$status = "" unless $status;
283
return "Manual (previous alternative setting)" if ( $status eq "manual" );
287
# -------------------------------------------------------------
288
sub dc_debconf_rebuild (){
289
# -------------------------------------------------------------
290
# Gather info from debconf for the (to be) installed packages for class
291
# %debconf_vals : pkg -> languages provided by package
292
# %debconf_defaultvals : pkg -> default language for package
293
# -------------------------------------------------------------
295
return unless $class;
296
my $question = "shared/packages-$class";
297
my ($errorcode,$pkgowners) = metaget ($question, "owners");
298
return if $errorcode;
301
%debconf_defaultvals = ();
302
foreach ( split (/\s*,\s*/,$pkgowners) ){
303
#$debconf_vals{$_} = metaget ("$_/languages", "default");
304
$debconf_vals{$_} = get ("$_/languages");
305
my ($errorcode,$pkgdefaults) = get ("$_/defaults");
306
$debconf_defaultvals{$_} = $pkgdefaults if not $errorcode;
311
# -----------------------------------------------------------------
313
&dc_debugprint("dictionaries-common: (re)configuring ...\n");
315
if ( not -e $dcscript ){
316
if ( -e "/etc/default/locale" ){
317
$language = $ENV{'LANG'} if exists $ENV{'LANG'};
319
&dc_debugprint("LANG is set to $language\n") if $language;
320
unless ( $language ){
321
($errorcode,$language) = get($di_language);
322
$language = '' if $errorcode;
323
&dc_debugprint("Debconf gives language: $language\n") if $language;
325
unless ( readlink ("/etc/alternatives/ispell-dictionary.hash") ||
326
readlink ("/etc/alternatives/dictionary")){
327
$language = $language ||
329
$ENV{'LC_MESSAGES'} ||
333
if ( $language ){ # Installing from scratch
334
$language = "en" if ( $language eq "C" );
335
# Deal with de_DE:de_DE@euro:de:en_GB.UTF-8:en like entries
336
$language = ( split(":",$language) )[0];
337
$language =~ s/[\.@].*$//; # Remove variant and charset
338
($language,$country) = split("_",$language);
340
($errorcode,$country) = get($di_country);
341
if ( $errorcode or not $country ){
345
foreach $class ("ispell","wordlist"){
346
$classprefix = substr($class,0,1);
347
if ( &dc_debconf_rebuild($class) ){
348
%pending_keys = %equivs;
349
if ( $guessed = &guesslang($class,$language,$country) ){
350
&dc_debugprint("* Guessed [d-i]->($class,$language,$country)\n");
351
&dc_set("dictionaries-common/default-$class","$guessed");
353
if ( $guessed = &guesslang($class,"en","US")
354
|| &guessotherlang ){
355
&dc_debugprint("*** Forcing [$guessed] for ($class,$language,$country) ***\n");
356
$priority{$class} = "medium";
357
&dc_set("dictionaries-common/default-$class","$guessed");
358
&dc_debugprint("** --- **\n");
360
&dc_debugprint("* Nothing found\n");
361
$priority{$class} = "critical";
366
} else { # Upgrading from woody or previous release
367
foreach ( keys %equivs ){
368
$reverse_equivs{$equivs{$_}} = $_;
370
&dc_debugprint("dictionaries-common: Trying pre-sarge symlinks\n");
371
foreach $class ("ispell","wordlist"){
372
$classprefix = substr($class,0,1);
373
if ( &dc_debconf_rebuild($class) ){
374
%pending_keys = %equivs;
375
if ( $guessed = &guesslang4link($class) ){
376
if ( &dc_manual_alternative($class) ){
377
&dc_debugprint("- $class was in manual mode. Setting critical priority\n");
378
$priority{$class} = "critical";
380
$priority{$class} = "low";
381
foreach ( keys %debconf_vals ){
383
next if ( $oldpackage eq "dictionaries-common" );
384
$oldpackage = "wenglish" if ( $oldpackage eq "wamerican" );
385
# critical priority if exists debconf entry without a
386
# previous package installed. This means that besides
387
# upgrading, new dicts are being installed.
388
if ( not -e "/var/lib/dpkg/info/$oldpackage.list" ){
389
$priority{$class} = "critical";
390
&dc_debugprint("* New dict [$oldpackage] is to be installed\n");
395
&dc_set("dictionaries-common/default-$class","$guessed");
402
# Unregistering no longer used dictionaries-common/languages and
403
# dictionaries-common ownership of other two shared questions
405
unregister("dictionaries-common/languages");
406
unregister("shared/packages-ispell");
407
unregister("shared/packages-wordlist");
409
# Prompting the questions if required
411
if ( not -e $dcscript ){ # First dictionaries-common installation
412
foreach $class ("ispell","wordlist"){
413
&dc_debconf_select($class,$priority{$class});
414
# This might have been pre-seeded and question not asked.
415
# Make sure question is tagged as seen in this case
416
if ( $priority{$class} ne "critical" ){
417
fset ("dictionaries-common/default-$class", "seen", "true");
421
} else { # Reconfiguring or upgrading
422
foreach $class ("ispell","wordlist"){
423
&dc_debconf_select($class);
427
&dc_debugprint("dictionaries-common: (re)configuring ...Done.\n");
430
# perl-indent-level: 2