2
# $Id: aspell-autobuildhash,v 1.5 2005/07/14 11:29:07 agmartin Exp $
4
# script for aspell hash autorebuild in Debian systems
6
# (c) 2004-2005 Agustin Martin Domingo <agmartin@debian.org>
9
# This program is free software; you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 2 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program; if not, write to the Free Software
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
print STDERR "\nUsage:\taspell-autobuildhash [--debug] [--force]\n"
28
. "\t--debug Show debugging information\n"
29
. "\t--force Do the job regardless of versions comparisons\n";
33
print STDERR "@_\n" if $debug;
37
my $message = join(" ",@_);
38
my $question = "dictionaries-common/ispell-autobuildhash-message";
44
$hashfile = "dictionaries-common";
47
subst($question,"xxpell","aspell");
48
subst($question,"XXpell","Aspell");
49
subst($question,"hashfile",$hashfile);
50
subst($question,"errormsg",$message);
51
fset ($question,"seen","false");
52
title("dictionaries-common: Running aspell-autobuildhash");
53
input("critical",$question);
62
# ---------------------------------------------------------------------
63
# Handle autorebuilding
64
# ---------------------------------------------------------------------
67
my $lang = shift || # The dictionary name
68
myerror "No argument passed to function autorebuild";
69
my $data = "/usr/lib/aspell"; # The data/lib dir
70
my $langsfile = "/usr/share/aspell/$lang.contents"; # The subdicts file
73
my $options = "--dont-validate-affixes" unless $debug;
75
myerror "aspell data dir $data does not exist" unless ( -d $data );
78
open (LANGSFILE, "< $langsfile") || die "Could not open $langsfile for reading";
79
@sublangs = <LANGSFILE>;
82
push @sublangs, $lang;
85
foreach ( @sublangs ){
94
my $base = "/usr/share/aspell/$sublang"; # the wordlist basename
95
my $hash = "/var/lib/aspell/$sublang.rws"; # the hash file
99
print STDERR "aspell-autobuildhash: processing: $lang [$sublang]\n";
102
if ( -e "$base.mwl.gz" ){
103
$unpack = "zcat $base.mwl.gz";
104
} elsif ( -e "$base.wl.gz") {
105
$unpack = "zcat $base.wl.gz";
106
} elsif ( -e "$base.cwl.gz") {
107
$unpack = "zcat $base.cwl.gz | precat";
109
mymessage "Could not find any of $base.{mwl,wl,cwl}.gz";
113
#$unpack = "$unpack | aspell clean strict";
114
system ("$unpack | aspell $options --local-data-dir=$data --lang=$lang create master $hash") == 0
115
or $msg = "Could not build the hash file for $sublang" ;
117
if ( $msg ){ # Do not break postinst if hash cannot be built
118
mymessage ($msg); # Just inform about that
125
# ---------------------------------------------------------------------
126
# Get aspell compat version
127
# ---------------------------------------------------------------------
129
sub get_aspell_compat {
131
my $aspell_compat = '';
133
if ( -e $aspellcompatfile ){
134
open (COMPAT,"$aspellcompatfile");
135
chomp ( $aspell_compat = <COMPAT> );
140
return $aspell_compat;
143
# ---------------------------------------------------------------------
145
# ---------------------------------------------------------------------
147
die "$0: You must run this as root.\n" if ($> != 0);
149
use Debconf::Client::ConfModule q(:all);
152
$compatdir = "/var/lib/aspell";
153
$aspellcompatfile = "/usr/share/aspell/aspell.compat";
158
GetOptions ('debug' => \$debug,
159
'force' => \$force) or usage();
161
if ( -x "/usr/bin/aspell" ){
163
$aspell_compat = get_aspell_compat();
165
foreach $compat ( <$compatdir/*.compat> ){
167
my $lang_compat = '';
170
$lang =~ s/\.compat$//;
173
open (COMPAT,"$compat");
174
$lang_compat = <COMPAT>;
176
$lang_compat = 0 if not $lang_compat;
179
$build_hash = "yes" if ( $aspell_compat ne $lang_compat );
180
$build_hash = "yes" if $force;
183
debugprint "$lang => aspell_compat: [$aspell_compat]; lang_compat: [$lang_compat]";
184
if ( autorebuild($lang) ){
185
debugprint " +++ Updating $compat";
186
open (COMPAT,">","$compat");
187
if ( $aspell_compat ){
188
print COMPAT "$aspell_compat\n";
194
debugprint " --- $compat not updated because of an error";
199
debugprint " aspell is not installed. Doing nothing";
206
B<aspell-autobuildhash> - Autobuilding aspell hash files for some dicts
210
aspell-autobuildhash [--force]
213
--debug Show some extra information.
214
--force Rebuild the hash file for all dicts providing a
215
compat file skipping the test.
219
B<aspell-autobuildhash> is a script that will manage aspell hash files
220
autobuild, intended to be called from the dictionaries-common tools.
221
Depending on the aspell
222
compatibility level and on the compatibility level used for the hash file
223
if present, will decide whether it must be rebuilt or not. This script will
224
only work on aspell packages prepared to use it, it will do nothing for other
225
aspell dict packages.
229
--debug Show some extra information.
230
--force Rebuild the hash file for all dicts providing a compat
231
file regardless of the compatibility levels found.
233
=head1 PACKAGE MAINTAINERS
235
To use this system, just provide a F<$lang.compat> file in F</var/lib/aspell>
236
(I<$lang> stands for the lang basename with variant if any, e.g. I<gl-minimos>
237
or I<en>). Put a "0" in it or just create an empty one with touch.
239
Wordlists should previously be compressed either with gzip
240
(and their extensions set as F<.mwl.gz> or F<.wl.gz>) or preferrably
241
first with aspell prezip and then gzipped (with F<.cwl.gz> extension).
242
This applies both for plain wordlists and munched wordlists
243
(in the ispell way) if you use affix compression.
245
If your package will provide a single hash, install prezipped+gzipped
246
wordlist as F</usr/share/aspell/$lang.cwl.gz> or, if prezip is not used,
247
as F</usr/share/aspell/$lang.mwl.gz>.
249
If your package will provide more than one aspell hash for the same $lang,
250
you will need to place each compressed wordlist as e.g.
251
F</usr/share/aspell/$subdict.cwl.gz>, and the common F<$lang.compat> as
252
above. Then create a F</usr/share/aspell/$lang.contents> file with the
253
base names of the subdicts, one in a line. For english that will contain,
254
amongst other possible lines
262
No need to use this file if a single hash is being created.
264
Dictionaries-common scripts will call internally this script and create a
265
single hash file at F</var/lib/ispell/$lang.hash>, or hash files at
266
F</var/lib/ispell/$subdict.hash>. You must set a symlink to that
267
files from F</usr/lib/aspell/$lang.hash> or
268
F</usr/lib/aspell/$subdict.hash> as appropriate.
269
You are also suggested to create empty files at
270
F</var/lib/aspell/$lang.hash> or for all of the
271
F</var/lib/aspell/$subdict.hash> in the install target of
272
your package build process. This empty file will be overwritten when the
273
real hash is created, but will make the hash be removed at package
274
removal without any magic being done in the postrm and will also help to
275
keep track about which package owns that file.
277
B<aspell> maintainer should also call this script from package postinst.
278
When comparing versions it will get the aspell version from file
279
F</usr/share/aspell/aspell.compat>.
283
Agustin Martin <agmartin@debian.org>