File: libvirt-daemon-system.postrm

package info (click to toggle)
libvirt 9.0.0-4%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 155,976 kB
  • sloc: ansic: 513,441; xml: 179,638; python: 10,469; sh: 3,737; perl: 2,769; makefile: 429; javascript: 116; cpp: 22
file content (148 lines) | stat: -rw-r--r-- 4,378 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/sh

set -e

# summary of how this script can be called:
#
#   * <postrm> `remove'
#   * <postrm> `purge'
#   * <old-postrm> `upgrade' <new-version>
#   * <disappearer's-postrm> `disappear' <overwriter> <overwriter-version>
#   * <new-postrm> `failed-upgrade' <old-version> <new-version>
#   * <new-postrm> `abort-install'
#   * <new-postrm> `abort-install' <old-version> <new-version>
#   * <new-postrm> `abort-upgrade' <old-version> <new-version>
#
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package

abort_conffile_transfer() {
    local conffile="$1"
    local lastver="$2"
    local pkgfrom="$3"
    local pkgto="$4"

    if [ "$5" != "--" ]; then
        echo "abort_conffile_transfer called with the wrong number of arguments" >&2
        return 1
    fi
    for _ in $(seq 1 5); do
        shift
    done

    # If we were installing from scratch or upgrading from a new enough version
    # when the error occurred, then no transfer was in progress and we don't
    # need to rollback any changes
    if [ -z "$2" ] || dpkg --compare-versions -- "$2" gt "$lastver"; then
        return 0
    fi

    # If the conffile was being transferred, return it to its original location
    if [ -e "$conffile.dpkg-transfer" ]; then
        mv -f "$conffile.dpkg-transfer" "$conffile"
    fi

    # Clean up additional state
    rm -f "$conffile.dpkg-disappear"
}

NWFILTERS="
    allow-arp
    allow-dhcp
    allow-dhcp-server
    allow-incoming-ipv4
    allow-ipv4
    clean-traffic
    clean-traffic-gateway
    no-arp-ip-spoofing
    no-arp-mac-spoofing
    no-arp-spoofing
    no-ip-multicast
    no-ip-spoofing
    no-mac-broadcast
    no-mac-spoofing
    no-other-l2-traffic
    no-other-rarp-traffic
    qemu-announce-self
    qemu-announce-self-rarp
"

case "$1" in
    purge)
        if getent group libvirt >/dev/null; then
            delgroup libvirt >/dev/null || true
        fi

        if getent passwd libvirt-qemu >/dev/null; then
            deluser libvirt-qemu >/dev/null || true
        fi

        if getent group libvirt-qemu >/dev/null; then
            delgroup libvirt-qemu >/dev/null || true
        fi

        # Clean up logs and cached capabilities
        rm -rf /var/log/libvirt \
               /var/cache/libvirt/qemu/capabilities

        # Clean up created dirs if existent and empty, they contain precious
        # data otherwise
        for dir in /var/lib/libvirt/qemu/save \
                   /var/lib/libvirt/qemu/snapshot \
                   /var/lib/libvirt/qemu/dump \
                   /var/lib/libvirt/qemu/nvram \
                   /var/lib/libvirt/qemu/ram/libvirt/qemu \
                   /var/lib/libvirt/qemu/ram/libvirt \
                   /var/lib/libvirt/qemu/ram \
                   /var/lib/libvirt/qemu/channel \
                   /var/lib/libvirt/qemu \
                   /var/cache/libvirt/qemu; do
            [ ! -d $dir ] || rmdir --ignore-fail-on-non-empty $dir
        done
    ;;

    abort-install|abort-upgrade)
        abort_conffile_transfer \
            "/etc/libvirt/qemu/networks/default.xml" \
            "6.9.0-2~" \
            "libvirt-daemon-system" \
            "libvirt-daemon-config-network" \
            -- \
            "$@"
        for nwfilter in $NWFILTERS; do
            abort_conffile_transfer \
                "/etc/libvirt/nwfilter/$nwfilter.xml" \
                "6.9.0-2~" \
                "libvirt-daemon-system" \
                "libvirt-daemon-config-nwfilter" \
                -- \
                "$@"
        done

        # dh_apparmor can't work with dir/file profile filenames yet (#979500)
        ABSTRACTIONS_DIR="/etc/apparmor.d/abstractions"
        LOCAL_ABSTRACTIONS_DIR="/etc/apparmor.d/local/abstractions"
        LIBVIRT_ABSTRACTIONS="libvirt-lxc libvirt-qemu"
        for name in $LIBVIRT_ABSTRACTIONS; do
            abstraction="$ABSTRACTIONS_DIR/$name"
            local_abstraction="$LOCAL_ABSTRACTIONS_DIR/$name"

            if [ ! -e "$abstraction" ] ; then
                rm -f "$local_abstraction"
                rmdir --ignore-fail-on-non-empty "$LOCAL_ABSTRACTIONS_DIR" 2>/dev/null
            fi
        done
    ;;

    remove|upgrade|disappear|failed-upgrade)
    ;;

    *)
        echo "postrm called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

#DEBHELPER#

exit 0