source: trunk/debathena/config/apparmor-config/debian/debathena-apparmor-config.postinst @ 25186

Revision 25186, 2.9 KB checked in by jdreed, 13 years ago (diff)
Deal with local profiles if applicable
Line 
1#!/bin/sh
2# postinst script for debathena-apparmor-config
3#
4# see: dh_installdeb(1)
5
6set -e
7
8# summary of how this script can be called:
9#        * <postinst> `configure' <most-recently-configured-version>
10#        * <old-postinst> `abort-upgrade' <new version>
11#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12#          <new-version>
13#        * <postinst> `abort-remove'
14#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
15#          <failed-install-package> <version> `removing'
16#          <conflicting-package> <version>
17# for details, see http://www.debian.org/doc/debian-policy/ or
18# the debian-policy package
19
20# dh_installdeb will replace this with shell code automatically
21# generated by other debhelper scripts.
22
23#DEBHELPER#
24
25package=debathena-apparmor-config
26ours=.debathena
27theirs=.debathena-orig
28
29undivert_unlink_symlink()
30{
31    file="$1"
32    ourfile="$2"
33    theirfile="$3"
34    if [ ! -L "$file" ] || \
35        [ "$(readlink "$file")" != "$(basename "$ourfile")" -a \
36          "$(readlink "$file")" != "$(basename "$theirfile")" ]; then
37        echo "*** OMINOUS WARNING ***: $file is not linked to either $(basename "$ourfile") or $(basename "$theirfile")" >&2
38    else
39        rm -f "$file"
40    fi
41}
42
43undivert_unlink_divert()
44{
45    file="$1"
46    if [ ! -L "$file" ] && [ ! -e "$file" ]; then
47        dpkg-divert --remove --rename --package "$package" "$file"
48    else
49        echo "Not removing diversion of $file by $package" >&2
50    fi
51}
52
53undivert_unlink()
54{
55    prefix=$1
56    suffix=$2
57
58    file=$prefix$suffix
59    ourfile=$prefix$ours$suffix
60    theirfile=$prefix$theirs$suffix
61
62    undivert_unlink_symlink "$file" "$ourfile" "$theirfile"
63    undivert_unlink_divert "$file" "$package"
64}
65
66cleanup_old_diversion() {
67    file="$1"
68    if dpkg-divert --list "${file}" | grep -Fxq "diversion of ${file} to ${file}${theirs} by ${package}"; then
69        undivert_unlink "$file"
70    fi
71}
72
73cleanup_old_removal() {
74    file="$1"
75    removedfile="$2"
76    if dpkg-divert --list "${file}" | grep -Fxq "diversion of ${file} to ${removedfile} by ${package}"; then
77        undivert_unlink_divert "$file"
78    fi
79}
80
81case "$1" in
82    configure)
83        if [ -d /etc/apparmor.d/tunables/home.d ]; then
84            cleanup_old_diversion /etc/apparmor.d/tunables/home
85        fi
86
87        # Ensure local files exist
88        # This should be replaced with something less stupid
89        if fgrep -q '#include <local/' /etc/apparmor.d/*.debathena; then
90          mkdir -p /etc/apparmor.d/local
91          for f in usr.sbin.cupsd usr.sbin.ntpd; do
92            [ -f "/etc/apparmor.d/local/$f" ] || touch "/etc/apparmor.d/local/$f"
93          done
94        fi
95
96        if hash apparmor_status 2>/dev/null && apparmor_status --enabled; then
97            if hash invoke-rc.d 2>/dev/null; then
98                invoke-rc.d apparmor reload
99            else
100                /etc/init.d/apparmor reload
101            fi
102        fi
103    ;;
104
105    abort-upgrade|abort-remove|abort-deconfigure)
106    ;;
107
108    *)
109        echo "postinst called with unknown argument \`$1'" >&2
110        exit 1
111    ;;
112esac
113
114exit 0
Note: See TracBrowser for help on using the repository browser.