/usr/sbin/aspell-autobuildhash is in dictionaries-common 1.12.1ubuntu2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | #!/usr/bin/perl -w
#
# script for aspell hash autorebuild in Debian systems
#
# Copyright 2004-2010 Agustin Martin Domingo <agmartin@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------------------------------------
use strict;
my $debug;
my $dry_run;
my $force;
my $triggered;
sub usage {
print STDERR "\nUsage:\taspell-autobuildhash [options]\n"
. "\n"
. "Options:\n"
. "\t--debug Show debugging infor about aspell-autobuildhash\n"
. "\t internal work. Will also enable aspell affix validation.\n"
. "\t--dry-run Show what would be done, but do nothing real.\n"
. "\t--force Do the job regardless of versions comparisons.\n"
. "\t--triggered Tell the script that is run in the triggers stage.\n";
}
sub debugprint {
print STDERR "@_\n" if $debug;
}
sub mymessage{
my $lang = shift;
my $message = join(" ",@_);
my $question = "dictionaries-common/ispell-autobuildhash-message";
subst($question,"xxpell","aspell");
subst($question,"XXpell","Aspell");
subst($question,"hashfile","$lang");
subst($question,"errormsg","$message");
fset ($question,"seen","false");
title("dictionaries-common: Running aspell-autobuildhash");
input("critical",$question);
go ();
}
sub myerror {
mymessage @_;
exit 1;
}
# ---------------------------------------------------------------------
# Handle autorebuilding
# ---------------------------------------------------------------------
sub autorebuild {
my $lang = shift || # The dictionary name
myerror("aspell-autobuildhash","No argument passed to function autorebuild");
my $data = "/usr/lib/aspell"; # The data/lib dir
my $langsfile = "/usr/share/aspell/$lang.contents"; # The subdicts file
my $options = " --per-conf= "; # Make sure no personal conf is used at all
my @sublangs = ();
$options .= " --dont-validate-affixes " unless $debug;
myerror "aspell data dir $data does not exist" unless ( -d $data );
if ( -e $langsfile ){
open (LANGSFILE, "< $langsfile") || die "Could not open $langsfile for reading";
@sublangs = <LANGSFILE>;
close LANGSFILE;
} else {
push @sublangs, $lang;
}
chomp @sublangs;
foreach ( @sublangs ){
next if m/^\s*$/;
next if m/^\s*\#/;
s/^\s+//;
s/\s+$//;
my $sublang = $_;
my $base = "/usr/share/aspell/$sublang"; # The wordlist basename
my $hash = "/var/lib/aspell/$sublang.rws"; # The hash file
my $msg = '';
my $unpack = '';
print STDERR "aspell-autobuildhash: processing: $lang [$sublang]\n";
if ( -e "$base.mwl.gz" ){
$unpack = "zcat $base.mwl.gz";
} elsif ( -e "$base.wl.gz") {
$unpack = "zcat $base.wl.gz";
} elsif ( -e "$base.cwl.gz") {
$unpack = "zcat $base.cwl.gz | precat";
} else {
mymessage($lang,"Could not find any of $base.{mwl,wl,cwl}.gz");
return 0;
}
#$unpack = "$unpack | aspell clean strict";
my $command = "$unpack | aspell $options --local-data-dir=$data --lang=$lang create master $hash";
if ( $dry_run ){
print STDERR "$command\n";
} else {
debugprint(" - command: $command");
system ("$command") == 0
or $msg = "Could not build the hash file for $sublang" ;
}
if ( $msg ){ # Do not break postinst if hash cannot be built
mymessage ($lang,$msg); # Just inform about that
return 0;
}
}
return 1;
}
# ---------------------------------------------------------------------
# Get aspell compat version
# ---------------------------------------------------------------------
sub get_aspell_compat {
my $aspell_compat;
my $aspellcompatfile = "/usr/share/aspell/aspell.compat";
if ( -e $aspellcompatfile ){
open (COMPAT,"$aspellcompatfile");
chomp ( $aspell_compat = <COMPAT> );
close COMPAT;
}
return $aspell_compat;
}
# ---------------------------------------------------------------------
# The main program
# ---------------------------------------------------------------------
use Debian::DictionariesCommon qw(dico_checkroot dico_activate_trigger);
use Debconf::Client::ConfModule q(:all);
use Getopt::Long;
# Check if we are root
dico_checkroot();
GetOptions ('debug' => \$debug,
'dry-run' => \$dry_run,
'force' => \$force,
'triggered' => \$triggered
) or usage();
my $compatdir = "/var/lib/aspell";
my $aspell_compat = get_aspell_compat();
unless ( $triggered or $force ) {
exit if dico_activate_trigger("aspell-autobuildhash");
}
$force++ unless $aspell_compat;
if ( system("which aspell > /dev/null 2>&1" ) == 0 ){
foreach my $compat ( <$compatdir/*.compat> ){
my $lang = $compat;
$lang =~ s/\.compat$//;
$lang =~ s/.*\///;
open (COMPAT,"$compat");
my $lang_compat = <COMPAT>;
close COMPAT;
chomp $lang_compat if $lang_compat;
$lang_compat = 0 unless $lang_compat;
if ( $force || $aspell_compat ne $lang_compat ){
print STDERR "--\n" if ( $debug or $dry_run );
debugprint "$lang => compat: \"$compat\", aspell_compat: [$aspell_compat]; lang_compat: [$lang_compat]";
if ( autorebuild($lang) ){
my $newcompat = $aspell_compat || 0;
if ( $dry_run ){
print STDERR "$newcompat > $compat\n"
} else {
open (COMPAT,">","$compat");
print COMPAT "$newcompat\n";
close COMPAT;
debugprint "Updated $compat to $newcompat";
}
} else {
debugprint " *=* $compat not updated because of an error";
}
}
}
} else {
debugprint " aspell is not installed. Doing nothing";
}
__END__
=head1 NAME
B<aspell-autobuildhash> - Autobuilding aspell hash files for some dicts
=head1 SYNOPSIS
aspell-autobuildhash [--force]
Options:
--debug Show extra info about aspell-autobuildhash internal
work. Will also enable aspell affix validation.
--dry-run Show what would be done, but do nothing real.
--force Rebuild the hash file for all dicts providing a
compat file skipping the test.
--triggered Tell the script that is run in the triggers stage.
=head1 DESCRIPTION
B<aspell-autobuildhash> is a script that will manage aspell hash files
autobuild, intended to be called from the dictionaries-common tools.
Depending on the aspell
compatibility level and on the compatibility level used for the hash file
if present, will decide whether it must be rebuilt or not. This script will
only work on aspell packages prepared to use it, it will do nothing for other
aspell dict packages.
=head1 OPTIONS
--debug Show some extra information about aspell-autobuildhash
internal work. Will also enable aspell affix validation.
--dry-run Show what would be done, but do nothing real.
--force Rebuild the hash file for all dicts providing a compat
file regardless of the compatibility levels found.
--triggered Tell the script that is run in the triggers stage. When
run under dpkg control, do not try to set the
'aspell-autobuildhash' trigger, but run real
B<aspell-autobuildhash> code. When not run under dpkg
control, real code will always be run and '--triggered'
option has no real effect.
=head1 PACKAGE MAINTAINERS
To use this system, B<aspell-autobuildhash> expects a F<$lang.compat> file
in F</var/lib/aspell> (I<$lang> stands for the lang basename with variant
if any, e.g. I<$lang> is something like I<gl-minimos> or I<en>))
containing aspell compatibility version for last successful build
or "0" or en empty file if hash is to be rebuild, as is for dictionary
instalation and upgrades.
When upgrading B<aspell>, script will check if version in I<$lang.compat>
is different from I<aspell.compat> and rebuild if so, updating
I<$lang.compat> with the new value.
Wordlists should previously be compressed either with gzip
(and their extensions set as F<.mwl.gz> or F<.wl.gz>) or preferably
first with aspell prezip and then gzipped (with F<.cwl.gz> extension).
This applies both for plain wordlists and munched wordlists
(in the ispell way) if you use affix compression.
If your package will provide a single hash, install prezipped+gzipped
wordlist as F</usr/share/aspell/$lang.cwl.gz> or, if prezip is not used,
as F</usr/share/aspell/$lang.mwl.gz>.
If your package will provide more than one aspell hash for the same $lang,
you will need to place each compressed wordlist as e.g.
F</usr/share/aspell/$subdict.cwl.gz>, and the common F<$lang.compat> as
above. Then create a F</usr/share/aspell/$lang.contents> file with the
base names of the subdicts, one in a line. For English that will contain,
amongst other possible lines
en-common
en-variant_0
en-variant_1
en-variant_2
en_CA-w_accents-only
No need to use this file if a single hash is being created.
Dictionaries-common scripts will call internally this script and create a
single hash file at F</var/lib/ispell/$lang.rws>, or hash files at
F</var/lib/ispell/$subdict.rws>. You must set a symlink to that
files from F</usr/lib/aspell/$lang.rws> or
F</usr/lib/aspell/$subdict.rws> as appropriate.
Aspell dictionary packages using this script must make sure that
I<$lang.compat> is reset on every new install/upgrade, so hash is rebuilt.
They must also make sure that I<$lang.compat> and all of
F</var/lib/aspell/$lang.rws> or F</var/lib/aspell/$subdict.rws>
are removed on package removal.
As of version C<1.10>, B<installdeb-aspell> script will understand
C<'auto-compat'> and C<'auto-contents'> fields in F<$dict.info-aspell>
file to help with this by adding needed debhelper snippets.
Put in that entry the base name(s) of your compat and contents file(s)
and carefully check resulting maintainer scripts after build.
Note that you are no longer suggested to ship empty files at
any of F</var/lib/aspell/$lang.compat>, F</var/lib/aspell/$lang.rws>
or F</var/lib/aspell/$subdict.rws>, but explicitly create/update them
on install and explicitly remove them on removal.
B<aspell> maintainer should also call this script from package postinst.
When comparing versions it will get the aspell version from file
F</usr/share/aspell/aspell.compat>.
=head1 AUTHORS
Agustin Martin <agmartin@debian.org>
=cut
|