#!/usr/bin/perl -w # # prerm maintainer script for the Debian autolatex-xxx package. # # summary of how this script can be called: # * remove # * purge # * upgrade # * failed-upgrade # * abort-install # * abort-install # * abort-upgrade # * disappear # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package use strict; use File::Copy; use Debconf::Client::ConfModule ':all'; my $CONFIG_FILE = '/etc/autolatex/default.cfg'; #-------------------------------------------------------------- # Print a message if in debug mode (see DEBCONF_DEBUG) sub printDbg(@) { if (($ENV{'DEBCONF_DEBUG'})&&($ENV{'DEBCONF_DEBUG'} eq 'developer')) { print STDERR ("AutoLaTeX config: ",@_,"\n"); } 1; } #-------------------------------------------------------------- # Search in array sub inarray($@) { my $elt = lc(shift); foreach my $e (@_) { if (lc($e) eq $elt) { return 1; } } return undef; } #-------------------------------------------------------------- # Remove a section sub removeSection($@) { my $filename = shift; printDbg("removable sections: ",join(' ',@_)); local *CFGFILE; open(*CFGFILE, "< $filename") or die("$filename: $!\n"); my $currentsection = undef; my $ignore = undef; my $fullcontent = ''; while (my $rline = ) { # Remove comments my $line = "$rline"; $line =~ s/\#[^\#]*$//; # Trim $line =~ s/^\s+//; $line =~ s/\s+$//; if ($line =~ /^\[([a-zA-Z0-9_+\-]+)\]$/s) { $currentsection = lc("$1"); $ignore = inarray("$currentsection",@_); printDbg("Detected section in configuration file: ",$currentsection); printDbg("Section ",$currentsection," is ", ($ignore?'':'not '),"removed"); } if (!$ignore) { $fullcontent .= "$rline"; } } close(*CFGFILE); $fullcontent =~ s/^\s+//s; $fullcontent =~ s/\s+$//s; open(*CFGFILE, "> $filename") or die("$filename: $!\n"); print CFGFILE "$fullcontent"; close CFGFILE; } printDbg("Running postrm translator configuration script for xxx2xxx with target ",$ARGV[0]); if ($ARGV[0] eq 'purge') { removeSection("$CONFIG_FILE", ###LOOP WITH , FROM 0### "xxx2xxx" ###END LOOP### ); } # When the postrm script is written in Shell, # the following lines are automatically added # by dh_installdebconf if ($ARGV[0] eq 'purge') { purge(); } # End automatically added section exit(0);