summaryrefslogtreecommitdiffstats
path: root/debian/bfh-container.preinst
blob: 2a6624f5e6100602d9e80ebf8284401d6b5335f4 (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
#!/bin/sh

set -e

case "${1}" in
	install|upgrade)
		mkdir -p /usr/lib/container/divert

		for FILE in halt poweroff reboot shutdown coldreboot
		do
			TRUENAME_USR="$(dpkg-divert --truename "/usr/sbin/${FILE}")"
			TRUENAME_ALIAS="$(dpkg-divert --truename "/sbin/${FILE}")"
			RENAME_FLAG="--no-rename"

			if [ "${TRUENAME_USR}" = "/usr/sbin/${FILE}" ]
			then
				if [ "${TRUENAME_ALIAS}" = "/sbin/${FILE}" ]
				then
					RENAME_FLAG="--rename"
				fi

				dpkg-divert --package bfh-container --quiet --add "${RENAME_FLAG}" --divert "/usr/lib/container/divert/${FILE}.orig" "/usr/sbin/${FILE}"
			fi

			# DEP17 M18 duplicated diversion, can be removed after trixie.
			if [ "${TRUENAME_ALIAS}" = "/sbin/${FILE}" ]
			then
				dpkg-divert --package bfh-container --quiet --add "${RENAME_FLAG}" --divert "/lib/container/divert/${FILE}.orig.usr-is-merged" "/sbin/${FILE}"
			elif [ "${TRUENAME_ALIAS}" != "/lib/container/divert/${FILE}.orig.usr-is-merged" ]
			then
				dpkg-divert --package bfh-container --quiet --remove --no-rename "/sbin/${FILE}"
				dpkg-divert --package bfh-container --quiet --add --no-rename --divert "/lib/container/divert/${FILE}.orig.usr-is-merged" "/sbin/${FILE}"

				if [ -e "${TRUENAME_ALIAS}" ] || [ -h "${TRUENAME_ALIAS}" ]
				then
					mv "${TRUENAME_ALIAS}" "/lib/container/divert/${FILE}.orig.usr-is-merged"
				fi
			fi
		done

		for FILE in pm-hibernate pm-suspend pm-suspend-hybrid
		do
			TRUENAME_USR="$(dpkg-divert --truename "/usr/sbin/${FILE}")"

			if [ "${TRUENAME_USR}" = "/lib/container/divert/${FILE}.orig" ]
			then
				dpkg-divert --package bfh-container --quiet --remove --no-rename "/usr/sbin/${FILE}"
				dpkg-divert --package bfh-container --quiet --add --no-rename --divert "/usr/lib/container/divert/${FILE}.orig" "/usr/sbin/${FILE}"
			else
				dpkg-divert --package bfh-container --quiet --add --rename --divert "/usr/lib/container/divert/${FILE}.orig" "/usr/sbin/${FILE}"
			fi
		done
		;;

	abort-upgrade)

		;;

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

#DEBHELPER#

exit 0