Remove obsolete config file diversions
[grml-etc.git] / debian / preinst
index aaebc30..2dd6aa2 100755 (executable)
@@ -4,16 +4,12 @@
 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
 # License:       This file is licensed under the GPL v2.
-# Latest change: Don Nov 02 20:58:57 CET 2006 [mika]
+# Latest change: Mon Feb 04 15:32:00 CET 2008 [mika]
 ################################################################################
 
 set -e
 
-TO_DIVERT1="login.config mgetty.config"
-TO_DIVERT2="ssh"
-TO_DIVERT3="kismet.conf"
-TO_DIVERT4="wlan-ng.conf"
-TO_DIVERT5="windowlab.menurc"
+TO_DIVERT1="ssh"
 
 divert_gen() {
     DEXT=${3:-original}
@@ -21,6 +17,12 @@ divert_gen() {
         --divert $2/$1.$DEXT $2/$1 > /dev/null
 }
 
+undivert_gen() {
+    DEXT=${3:-original}
+    dpkg-divert --remove --rename --package grml-etc \
+        --divert $2/$1.$DEXT $2/$1 #> /dev/null
+}
+
 # move files from package grml-etc to grml-etc-core
 # and make sure we do not lose any files...
 rm_conffile() {
@@ -28,9 +30,10 @@ rm_conffile() {
 
     if [ -e "$CONFFILE" ]; then
         md5sum="`md5sum \"$CONFFILE\" | sed -e \"s/ .*//\"`"
-        old_md5sum="`sed -n -e \"/^Conffiles:/,/^[^ ]/{\\\\' $CONFFILE'{s/.* //;p}}\" /var/lib/dpkg/status`"
+        old_md5sum="`dpkg-query -W -f='${Conffiles}' grml-etc | sed -n -e \"\\\\' $CONFFILE'{s/ obsolete$//;s/.* //p}\"`"
         if [ "$md5sum" != "$old_md5sum" ]; then
-            echo "Conffile $CONFFILE has been modified, temporary moving to $CONFFILE.dpkg-bak ..."
+            echo "Obsolete conffile $CONFFILE has been modified by you."
+            echo "Saving as $CONFFILE.dpkg-bak ..."
             mv -f "$CONFFILE" "$CONFFILE".dpkg-bak
         fi
     fi
@@ -39,34 +42,17 @@ rm_conffile() {
 case "$1" in
    install|upgrade)
         for cmd in $TO_DIVERT1; do
-                divert_gen $cmd /etc/mgetty
-        done
-        for cmd in $TO_DIVERT2; do
-                divert_gen $cmd /etc/init.d
-        done
-        for cmd in $TO_DIVERT3; do
-                divert_gen $cmd /etc/kismet
-        done
-        for cmd in $TO_DIVERT4; do
-                divert_gen $cmd /etc/pcmcia
-        done
-        for cmd in $TO_DIVERT5; do
-                divert_gen $cmd /etc/X11/windowlab
+            divert_gen $cmd /etc/init.d
         done
 
-        # did I mention that dpkg-divert sucks?
-        if [ -n "$2" ] ; then
-           if dpkg --compare-versions "${2}" lt 0.8 ; then
-              if dpkg-divert --list | grep -q /etc/init.d/postgresql-8.0 ; then
-                 rm -f /etc/init.d/postgresql-8.0
-                 dpkg-divert --quiet --package grml-etc --remove --rename --divert /etc/init.d/postgresql-8.0.original /etc/init.d/postgresql-8.0
-              fi
-           fi
-        fi
+        # Remove files we no longer ship
+        undivert_gen "kismet.conf" /etc/kismet
+        undivert_gen "wlan-ng.conf" /etc/pcmcia
+        undivert_gen "smb.conf" /etc/samba
 
-        # move files from package grml-etc to grml-etc-core / remove them at all
+        # move files from package grml-etc to grml-etc-core
         for file in /etc/zsh/zlogin /etc/zsh/zprofile /etc/zsh/zshenv /etc/zsh/zshrc \
-                    /etc/zsh/zshrc  /etc/zsh/zlogout  /etc/vim/vimrc  /etc/samba/smb.conf ; do
+                    /etc/zsh/zshrc  /etc/zsh/zlogout  /etc/vim/vimrc ; do
             if dpkg-divert --list $file | grep -q 'grml-etc$' ; then
                rm_conffile $file
                dpkg-divert --quiet --package grml-etc --remove --rename --divert $file.original $file
@@ -84,6 +70,8 @@ case "$1" in
      exit 1
 esac
 
+#DEBHELPER#
+
 exit 0
 
 ## END OF FILE #################################################################