summaryrefslogtreecommitdiffstats
path: root/debian/molly-guard.preinst
blob: 1dcd2200679f8735d414d095089b831816b3502e (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
69
70
71
72
73
#!/bin/sh
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    install|upgrade)
        for cmd in halt poweroff reboot shutdown coldreboot ; do
            truenameusr="$(dpkg-divert --truename "/usr/sbin/$cmd")"
            truenamealias="$(dpkg-divert --truename "/sbin/$cmd")"
            rename_flag=--no-rename
	    if test "$truenameusr" = "/usr/sbin/$cmd" && test "$truenamealias" = "/sbin/$cmd"; then
                rename_flag=--rename
            fi
            if test "$truenameusr" = "/usr/sbin/$cmd"; then
                dpkg-divert --package molly-guard --divert "/usr/sbin/$cmd.no-molly-guard" "$rename_flag" --add "/usr/sbin/$cmd"
            elif test "$truenameusr" != "/usr/sbin/$cmd.no-molly-guard"; then
                dpkg-divert --package molly-guard --no-rename --remove  "/usr/sbin/$cmd"
                dpkg-divert --package molly-guard --no-rename --divert "/usr/sbin/$cmd.no-molly-guard" --add "/usr/sbin/$cmd"
                if test -e "$truenameusr" || test -h "$truenameusr"; then
                    mv "$truenameusr" "/usr/sbin/$cmd.no-molly-guard"
                fi
            fi
            if test "$truenamealias" = "/sbin/$cmd"; then
                # DEP17 M18 duplicated diversion. Can be --removed after trixie.
                dpkg-divert --package molly-guard --divert "/sbin/$cmd.no-molly-guard.usr-is-merged" "$rename_flag" --add "/sbin/$cmd"
            elif test "$truenamealias" != "/sbin/$cmd.no-molly-guard.usr-is-merged"; then
                dpkg-divert --package molly-guard --no-rename --remove  "/sbin/$cmd"
                dpkg-divert --package molly-guard --no-rename --divert "/sbin/$cmd.no-molly-guard.usr-is-merged" --add "/sbin/$cmd"
                if test -e "$truenamealias" || test -h "$truenamealias"; then
                    mv "$truenamealias" "/sbin/$cmd.no-molly-guard.usr-is-merged"
                fi
            fi
        done

        for cmd in pm-hibernate pm-suspend pm-suspend-hybrid ; do
            truename="$(dpkg-divert --truename "/usr/sbin/$cmd")"
            if test "$truename" = "/usr/sbin/$cmd"; then
                dpkg-divert --package molly-guard --divert "/usr/sbin/$cmd.no-molly-guard" --rename "/usr/sbin/$cmd"
            elif test "$truename" != "/usr/sbin/$cmd.no-molly-guard"; then
                dpkg-divert --package molly-guard --no-rename --remove "/usr/sbin/$cmd"
                dpkg-divert --package molly-guard --divert "/usr/sbin/$cmd.no-molly-guard" --no-rename --add "/usr/sbin/$cmd"
                if test -e "$truename" -o -h "$truename"; then
                     mv "$truename" "/usr/sbin/$cmd.no-molly-guard"
                fi
            fi
        done
    ;;

    abort-upgrade)
    ;;

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

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0