summaryrefslogtreecommitdiff
path: root/debian/x11-common.postrm.in
blob: 22bf8b8155ca6c84b565fd31e145c7383eae5bb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
# Debian x11-common package post-removal script
# Copyright 1998--2001, 2003 Branden Robinson.
# Licensed under the GNU General Public License, version 2.  See the file
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
# Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.


set -e

THIS_PACKAGE=x11-common
THIS_SCRIPT=postrm
CONFIG_DIR=/etc/X11
XWRAPPER_CONFIG="$CONFIG_DIR/Xwrapper.config"
CONFIG_AUX_DIR=/var/lib/x11
XWRAPPER_CONFIG_CHECKSUM="$CONFIG_AUX_DIR/${XWRAPPER_CONFIG##*/}.md5sum"
XWRAPPER_CONFIG_ROSTER="$CONFIG_AUX_DIR/${XWRAPPER_CONFIG##*/}.roster"

#INCLUDE_SHELL_LIB#

# clean up non-conffile configuration files and related materials on purge
if [ "$1" = "purge" ]; then
  # de-register this package as a handler of the X server wrapper config file
  if [ -e "$XWRAPPER_CONFIG_ROSTER" ]; then
    # check existing roster file for our package name
    if fgrep -qx "$THIS_PACKAGE" "$XWRAPPER_CONFIG_ROSTER" 2>/dev/null; then
      # construct temporary roster file with our package name removed, ignoring
      # failure
      fgrep -vx "$THIS_PACKAGE" "$XWRAPPER_CONFIG_ROSTER" > \
        "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp" 2>/dev/null || true
      # is there anything left?
      if [ -s "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp" ]; then
        # yes, replace the roster file
        mv "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp" "$XWRAPPER_CONFIG_ROSTER"
      else
        # no; remove both the roster and our temporary copy
        rm -f "$XWRAPPER_CONFIG_ROSTER" "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp"
        # remove X server wrapper config file if it was still managed by the
        # package
        if [ -e "$XWRAPPER_CONFIG_CHECKSUM" ]; then
          # does it exist?
          if [ -e "$XWRAPPER_CONFIG" ]; then
            # does the current MD5 checksum match the stored checksum?
            if [ "$(md5sum "$XWRAPPER_CONFIG")" \
                 = "$(cat "$XWRAPPER_CONFIG_CHECKSUM")" ]; then
              # yes; remove the config file
              rm -f "$XWRAPPER_CONFIG"
            fi
          fi
          # remove the checksum file; any remaining X server wrapper config file
          # still on the system at this point is no longer being managed (local
          # user customization)
          rm -f "$XWRAPPER_CONFIG_CHECKSUM"
        fi
      fi
    fi
  fi

  for DIR in "$CONFIG_DIR" "$CONFIG_AUX_DIR"; do
      rmdir "$DIR" 2> /dev/null || true
  done
fi

#DEBHELPER#

exit 0

# vim:set ai et sts=2 sw=2 tw=80: