home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / sbin / update-default-wordlist < prev    next >
Encoding:
Text File  |  2006-07-12  |  4.0 KB  |  152 lines

  1. #!/usr/bin/perl -w
  2.  
  3. use Debian::DictionariesCommon q(:all);
  4. use Debconf::Client::ConfModule q(:all);
  5. use Getopt::Long;
  6.  
  7. die "$0: You must run this as root.\n" if ($> != 0);
  8.  
  9. my $rebuild = '';
  10. my $ignoresymlinks = '';
  11.  
  12. GetOptions ('rebuild' => \$rebuild,
  13.         'ignore-symlinks' => \$ignoresymlinks);
  14.  
  15. version ('2.0');
  16.  
  17. my $class     = "wordlist";
  18. my $libdir    = "/usr/share/dict";
  19. my $question  = "dictionaries-common/default-$class";
  20. my $iquestion = "dictionaries-common/invalid_debconf_value";
  21. my $linkdir   = "/etc/dictionaries-common";
  22. my $manual    = '';
  23.  
  24.  
  25. ($ret, $value)  = get ($question);
  26.  
  27. if ($ret == 0 && $value ){
  28.   
  29.   updatedb ($class);
  30.   my $dictionaries = loaddb ($class);
  31.   
  32.   if ( scalar(keys %{$dictionaries}) == 0 ){
  33.     print STDERR "$0 No $class elements installed.\n";
  34.     $value = "Manual forced (No $class elements installed)";
  35.     set($question,$value);
  36.     go();
  37.   }
  38.   
  39.   if ( $value =~ m/^Manual.*/i ){       # Check if we are in manual mode
  40.     $ignoresymlinks = "yes";
  41.     $manual         = "yes";
  42.   }
  43.  
  44.   if ( not $ignoresymlinks) {
  45.     
  46.     if (not exists $dictionaries->{$value}){         # Handle invalid debconf values
  47.       my @available_keys=();
  48.       foreach ( split (/\s*,\s*/, metaget ($question, "choices")) ){
  49.     s/\s*(.*)\s*/$1/;          # strip possible leading/trailing whitespaces
  50.     push (@available_keys,$_) if ( exists $dictionaries->{$_} );
  51.       }
  52.       my $choices = join (', ', sort {lc $a cmp lc $b} @available_keys);
  53.       my $forced_key = $available_keys[0] ||
  54.       die "Selected wordlist:\n" .
  55.       " $value \n" .
  56.       "does not correspond to any installed package in the system\n" .
  57.       "and no alternative wordlist could be selected.\n";
  58.       subst($iquestion,"value",$value);
  59.       fset ($iquestion,"seen","false");
  60.       input("high",$iquestion);               # Warn about what happened
  61.       subst ($question, "choices", $choices); # Put sane values in debconf choices field
  62.       set ($question, $forced_key);           # Set debconf value to a sane one  
  63.       fset ($question,"seen","false");
  64.       input ("critical", $question);  
  65.       title ("dictionaries-common: wordlists");
  66.       go ();
  67.       ($ret, $value) = get ($question);
  68.       die "\n Could not get a valid value for debconf question:\n" .
  69.       "$question\n"
  70.           if ( $ret != 0 ); # This should never be reached
  71.     }
  72.     
  73.     die "Selected wordlist:\n" .
  74.     " $value \n" .
  75.     "does not contain a hash name entry in the database.\n"
  76.     if (not exists $dictionaries->{$value}{"hash-name"});
  77.  
  78.     my $hash   = "$libdir/" . $dictionaries->{$value}{"hash-name"};
  79.  
  80.     foreach my $i ("") {
  81.  
  82.       die "
  83. When trying to make the default link to a wordlist
  84. the file to link [$hash$i] was not found. Please report this as a bug to the
  85. maintainer of the wordlist package you tried to
  86. select.
  87. In the meantime select other default value for your wordlist.\n"
  88. if (not -e "$hash$i");
  89.       
  90.       system "ln -fs $hash$i $linkdir/words$i";
  91.       
  92.     }
  93.   }
  94.  
  95. }
  96.  
  97.  
  98.  
  99. if ($rebuild) {
  100.  
  101.   updatedb ($class);
  102.  
  103.   # (nothing to do for wordlists)
  104. }
  105.  
  106. #Local Variables:
  107. #perl-indent-level: 2
  108. #End:
  109.  
  110. __END__
  111.  
  112. =head1 NAME
  113.  
  114. update-default-wordlist - update default wordlist 
  115.  
  116. =head1 SYNOPSIS
  117.  
  118.  update-default-wordlist [--rebuild] [--ignore-symlinks]
  119.  
  120. =head1 DESCRIPTION
  121.  
  122. WARNING: Not to be used from the command line unless you know very well what you are doing. 
  123.  
  124. This program is intended to be called from package postinst 
  125. (with B<--rebuild>), from B<select-default-wordlist> or 
  126. from dictionaries-common 
  127. postinst (with B<--ignore-symlinks>).
  128.  
  129. Reads the system default from the debconf database and set default links in 
  130. F</etc/dictionaries-common> pointing to the appropriate files in 
  131. F</usr/share/dict/>. 
  132. If option B<--rebuild> is given, rebuilds the 
  133. F</var/cache/dictionaries-common/wordlist.db>  from the files in
  134. F</var/lib/dictionaries-common/wordlist>
  135.  
  136.  
  137. =head1 OPTIONS
  138.  
  139. --rebuild          Rebuild database, emacsen and jed stuff
  140. --ignore-symlinks  Do not set symlinks
  141.  
  142.  
  143. =head1 SEE ALSO
  144.  
  145. The dictionaries-common policy document
  146.  
  147. =head1 AUTHORS
  148.  
  149. Rafael Laboissiere
  150.  
  151. =cut
  152.