Really fix /etc/grml/lsb-functions :)
[grml-etc-core.git] / debian / preinst
1 #!/bin/sh
2 # Filename:      preinst
3 # Purpose:       preinst script for package grml-etc-core
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Sam Sep 15 10:36:46 CEST 2007 [mika]
8 ################################################################################
9
10 set -e
11
12 # check for files from rm_conffile() in debian/preinst of grml-etc
13 # make sure we don't lose any files...
14 backup_conffile() {
15     CONFFILE="$1"
16
17     if [ -e "$CONFFILE.dpkg-bak" -a -e "$CONFFILE" ]; then
18        cp -f "$CONFFILE" "$CONFFILE".original
19     else
20        [ -e "$CONFFILE" ] && cp -f "$CONFFILE" "$CONFFILE".grml-etc-core || true
21     fi
22 }
23
24 case "$1" in
25    install|upgrade|configure)
26         TMP=$$
27         # move files from package grml-etc to grml-etc-core, make sure
28         # we don't lose any files...
29         for file in /etc/zsh/zlogin /etc/zsh/zprofile /etc/zsh/zshenv /etc/zsh/zshrc \
30                     /etc/zsh/zlogout /etc/vim/vimrc; do
31                [ -e "$file".original ] || cp -f "$file" "${file}.tmp.$TMP" 2>/dev/null || /bin/true
32                # [ -e "$file".dpkg-new ] && cp -f "$file".dpkg-new "${file}.tmp.$TMP"
33                backup_conffile $file && \
34                [ -f "$file" ] && rm $file && \
35                dpkg-divert --quiet --add --rename --package grml-etc-core --divert "$file".original $file  && \
36                [ -f "$file".dpkg-bak ]      && mv -f "$file".dpkg-bak "$file"
37                [ -f "$file".grml-etc-core ] && mv -f "$file".grml-etc-core "$file"
38                [ -e "${file}.tmp.$TMP" ]      && mv -f "${file}.tmp.$TMP" "$file.original"
39
40                # trying to overwrite `/etc/skel/.zshrc', which is also in package zsh
41                # [ -f /etc/skel/.zshrc ] && \
42                # dpkg-divert --quiet --add --rename --package grml-etc-core --divert /etc/skel/.zshrc.original /etc/skel/.zshrc
43         done
44
45         if dpkg-divert --list grml-etc-core 2>/dev/null | grep -q /etc/skel/.zshrc.original ; then
46            mv -f /etc/skel/.zshrc.original /etc/skel/.zshrc.original.old && \
47            dpkg-divert --remove --rename --package grml-etc-core /etc/skel/.zshrc
48         fi
49
50      ;;
51    *)
52      echo "preinst called with unknown argument $1" >&2
53      exit 1
54 esac
55
56 exit 0
57
58 ## END OF FILE #################################################################