6fc8ab407c98afc49be1486087b7bfc43047e914
[grml-etc.git] / debian / preinst
1 #!/bin/sh
2 # Filename:      preinst
3 # Purpose:       preinst script for package grml-etc
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: Don Okt 12 17:39:16 CEST 2006 [mika]
8 ################################################################################
9
10 set -e
11
12 TO_DIVERT1="login.config mgetty.config"
13 TO_DIVERT2="ssh"
14 TO_DIVERT3="kismet.conf"
15 TO_DIVERT4="wlan-ng.conf"
16 TO_DIVERT5="smb.conf"
17 TO_DIVERT6="windowlab.menurc"
18
19 divert_gen() {
20     DEXT=${3:-original}
21     dpkg-divert --add --rename --package grml-etc \
22         --divert $2/$1.$DEXT $2/$1 > /dev/null
23 }
24
25 # move files from package grml-etc to grml-etc-core
26 # and make sure we do not lose any files...
27 rm_conffile() {
28     CONFFILE="$1"
29
30     if [ -e "$CONFFILE" ]; then
31         md5sum="`md5sum \"$CONFFILE\" | sed -e \"s/ .*//\"`"
32         old_md5sum="`sed -n -e \"/^Conffiles:/,/^[^ ]/{\\\\' $CONFFILE'{s/.* //;p}}\" /var/lib/dpkg/status`"
33         if [ "$md5sum" != "$old_md5sum" ]; then
34             echo "Conffile $CONFFILE has been modified, temporary moving to $CONFFILE.dpkg-bak ..."
35             mv -f "$CONFFILE" "$CONFFILE".dpkg-bak
36         fi
37     fi
38 }
39
40 case "$1" in
41    install|upgrade)
42         for cmd in $TO_DIVERT1; do
43                 divert_gen $cmd /etc/mgetty
44         done
45         for cmd in $TO_DIVERT2; do
46                 divert_gen $cmd /etc/init.d
47         done
48         for cmd in $TO_DIVERT3; do
49                 divert_gen $cmd /etc/kismet
50         done
51         for cmd in $TO_DIVERT4; do
52                 divert_gen $cmd /etc/pcmcia
53         done
54         for cmd in $TO_DIVERT5; do
55                 divert_gen $cmd /etc/samba
56         done
57         for cmd in $TO_DIVERT6; do
58                 divert_gen $cmd /etc/X11/windowlab
59         done
60
61         # did I mention that dpkg-divert sucks?
62         if [ -n "$2" ] ; then
63            if dpkg --compare-versions "${2}" lt 0.8 ; then
64               if dpkg-divert --list | grep -q /etc/init.d/postgresql-8.0 ; then
65                  rm -f /etc/init.d/postgresql-8.0
66                  dpkg-divert --quiet --package grml-etc --remove --rename --divert /etc/init.d/postgresql-8.0.original /etc/init.d/postgresql-8.0
67               fi
68            fi
69         fi
70
71         # move files from package grml-etc to grml-etc-core
72         for file in /etc/zsh/zlogin /etc/zsh/zprofile /etc/zsh/zshenv /etc/zsh/zshrc \
73                     /etc/zsh/zshrc  /etc/zsh/zlogout  /etc/vim/vimrc ; do
74             if dpkg-divert --list $file | grep -q 'grml-etc$' ; then
75                rm_conffile $file
76                dpkg-divert --quiet --package grml-etc --remove --rename --divert $file.original $file
77             fi
78         done
79
80         if dpkg-divert --list /etc/skel/.zshrc | grep -q 'grml-etc$' ; then
81            [ -f /etc/skel/.zshrc.original ] && rm /etc/skel/.zshrc
82            dpkg-divert --quiet --package grml-etc --remove --rename --divert /etc/skel/.zshrc.original /etc/skel/.zshrc
83         fi
84
85      ;;
86    *)
87      echo "preinst called with unknown argument $1" >&2
88      exit 1
89 esac
90
91 exit 0
92
93 ## END OF FILE #################################################################