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