Reportcourier-filter-perlpostinst

Status: Accepted

Colis script


function mv_conffile_to_noncf begin
                                OLDCONFFILE := arg 1 ;
                                NEWCONFFILE := arg 2 ;
                                if [ [ '-e'; OLDCONFFILE; ']' ]
                                then begin
                                       echo [ 'Preserving user changes in '
                                              OLDCONFFILE ' to ' NEWCONFFILE
                                              ' ...' ] ;
                                       mv [ '-f'; OLDCONFFILE; NEWCONFFILE ]
                                  end
                                fi
end
function mv_conffile begin
                       OLDCONFFILE := arg 1 ;
                       NEWCONFFILE := arg 2 ;
                       if [ [ '-e'; OLDCONFFILE; ']' ]
                       then begin
                              echo [ 'Preserving user changes in '
                                     OLDCONFFILE ' to ' NEWCONFFILE ' ...' ] ;
                              mv [ '-f'; NEWCONFFILE;
                                 NEWCONFFILE '.dpkg-new' ] ;
                              mv [ '-f'; OLDCONFFILE; NEWCONFFILE ]
                         end
                       fi
end
begin
  true ;
  mode := arg 1 ;
  true ;
  true ;
  case_8566211 := mode ;
  if test [ case_8566211; '='; 'configure' ]
  then begin
         old_version := arg 2 ;
         config_file := '/etc/courier/filters/courier-filter-perl.conf' ;
         if dpkg [ '--compare-versions'; old_version; 'lt'; '0.200' ]
         then call mv_conffile_to_noncf [ '/etc/courier/filters/pureperlfilter.conf';
                                        split config_file ]
         fi ;
         if [ [ '!'; '-e'; split config_file; ']' ]
         then cp [ '/usr/share/courier-filter-perl/courier-filter-perl.conf.bare';
                 split config_file ]
         fi ;
         echo [ 'Starting courier-filter-perl mail filter ...' ] ;
         filterctl [ 'start'; 'courier-filter-perl' ]
    end
  fi
end

Original Shell script

#!/bin/sh

set -e

mode=$1

# Move a conffile without triggering a dpkg question
mv_conffile() {
    OLDCONFFILE="$1"
    NEWCONFFILE="$2"

    if [ -e "$OLDCONFFILE" ]; then
        echo "Preserving user changes in $OLDCONFFILE to $NEWCONFFILE ..."
        mv -f "$NEWCONFFILE" "$NEWCONFFILE".dpkg-new
        mv -f "$OLDCONFFILE" "$NEWCONFFILE"
    fi
}

# Move a conffile to a non-conffile
mv_conffile_to_noncf() {
    OLDCONFFILE="$1"
    NEWCONFFILE="$2"

    if [ -e "$OLDCONFFILE" ]; then
        echo "Preserving user changes in $OLDCONFFILE to $NEWCONFFILE ..."
        mv -f "$OLDCONFFILE" "$NEWCONFFILE"
    fi
}

case "$mode" in
  configure )
    old_version=$2
    
    config_file=/etc/courier/filters/courier-filter-perl.conf
    
    if dpkg --compare-versions "$old_version" lt "0.200"; then
        # Preserve customized old config file, if any:
        mv_conffile_to_noncf /etc/courier/filters/pureperlfilter.conf $config_file
    fi
    
    if [ ! -e $config_file ]; then
        # No config file exists, create one:
        cp /usr/share/courier-filter-perl/courier-filter-perl.conf.bare $config_file
    fi
    
    echo "Starting courier-filter-perl mail filter ..."
    filterctl start courier-filter-perl
    ;;
esac