Another version of dpkg-divert handling for debian/preinst.
[grml-etc-core.git] / debian / preinst
index 848ecff..64f5164 100755 (executable)
@@ -4,22 +4,21 @@
 # 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: Fre Feb 09 15:24:01 CET 2007 [mika]
+# Latest change: Mit Mär 21 19:03:31 CET 2007 [mika]
 ################################################################################
 
 set -e
 
 # check for files from rm_conffile() in debian/preinst of grml-etc
 # make sure we don't lose any files...
-divert_conffile() {
+backup_conffile() {
     CONFFILE="$1"
 
-    if [ -e "$CONFFILE.dpkg-bak" ]; then
+    if [ -e "$CONFFILE.dpkg-bak" -a -e "$CONFFILE" ]; then
        cp -f "$CONFFILE" "$CONFFILE".original
     else
-       [ -e "$CONFFILE" ] && cp -f "$CONFFILE" "$CONFFILE".grml-etc-core
+       [ -e "$CONFFILE" ] && cp -f "$CONFFILE" "$CONFFILE".grml-etc-core || true
     fi
-
 }
 
 case "$1" in
@@ -29,8 +28,8 @@ case "$1" in
         # we don't lose any files...
         for file in /etc/zsh/zlogin /etc/zsh/zprofile /etc/zsh/zshenv /etc/zsh/zshrc \
                     /etc/zsh/zlogout /etc/vim/vimrc; do
-               [ -e "$file".original ] || cp -f "$file" "${file}.tmp.$$"
-               divert_conffile $file && \
+               [ -e "$file".original ] || cp -f "$file" "${file}.tmp.$$" || /bin/true
+               backup_conffile $file && \
                [ -f "$file" ] && rm $file && \
                dpkg-divert --quiet --add --rename --package grml-etc-core --divert "$file".original $file  && \
                [ -f "$file".dpkg-bak ]      && mv -f "$file".dpkg-bak "$file"