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
|
#!/usr/bin/perl
# wfrench.postinst
# Written by Charles Briscoe-Smith <cpbs@debian.org> based loosely on
# an older, unattributed, script. I release this to the Public Domain.
# Ask <cpbs@debian.org> if you have problems with this script.
$| = 1; # Flush the buffer for every print out.
$LANGUAGE = "french";
$words = "/usr/dict/words";
$dict = "/etc/dictionary";
$dict_rel_words = "../../etc/dictionary";
$lang = "/usr/dict/$LANGUAGE";
$action = shift @ARGV;
# If we're configuring and $dict doesn't exist, ask whether we should
# be the default dictionary.
if ( $action eq "configure" and ! -e $dict ) {
# If $dict is a broken symlink, get it out of the way.
if ( -l $dict ) {
rename $dict, "$dict.old"
or die "Can't backup broken symlink `$dict' as `$dict.old'.\n";
warn "Backed up broken symlink `$dict' as `$dict.old'.\n";
}
print "Would you like $LANGUAGE to be the default dictionary? [y/N]: ";
if ( <STDIN> =~ m/^y/i ) {
symlink $lang, $dict
or die "Can't create symlink `$dict' pointing to `$lang'.\n";
print "\nMade $LANGUAGE the default dictionary. (You can change this by\n";
print "adjusting the symbolic link `$dict' - see `man ln'.)\n";
}
}
# If $dict was already something else, tell someone about it.
if ( -e $dict and ! -l $dict ) {
warn "`$dict' should be a symlink to a dictionary in `/usr/dict'.\n";
}
# Now that $dict should be valid, ensure $words points to $dict.
unless ( -l $words and readlink $words eq $dict ) {
if ( -l $words and readlink $words eq $dict_rel_words ) {
# Clean up old relative symlink neatly.
unlink $words or die "Can't remove `$words'.\n";
}
elsif ( -e $words ) {
rename $words, "$words.old"
or die "Can't backup `$words' as `$words.old'.\n";
warn "Backed up `$words' as `$words.old'.\n";
}
elsif ( -l $words ) {
rename $words, "$words.old"
or die "Can't backup broken symlink `$words' as `$words.old'.\n";
warn "Backed up broken symlink `$words' as `$words.old'.\n";
}
symlink $dict, $words
or die "Can't create symlink `$words' pointing to `$dict'.\n";
}
|