File: postrm

package info (click to toggle)
resolvconf 1.79
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 500 kB
  • ctags: 43
  • sloc: sh: 915; makefile: 40
file content (117 lines) | stat: -rwxr-xr-x 3,056 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

set -e

. /usr/share/debconf/confmodule

MYNAME=resolvconf.postrm
report() { echo "${MYNAME}: $*" ; }
report_info() { report "$*" >&2 ; }

is_installed() {
	# Same function in preinst, postinst, postrm
	[ "$1" ] || return 1
	dpkg-query -W -f='${Status}\n' "$1" 2>/dev/null | grep -siq '^[[:alpha:]]\+ [[:alpha:]]\+ installed$' >/dev/null 2>&1
}

#DEBHELPER#

case "$1" in
  remove)
	if
		[ -L /etc/resolv.conf ] \
		&& {
			[ "$(readlink /etc/resolv.conf)" = "/etc/resolvconf/run/resolv.conf" ] \
			|| [ "$(readlink /etc/resolv.conf)" = "resolvconf/run/resolv.conf" ]
		}
	then
		# /etc/resolv.conf is a resolvconf symlink

		#
		# Remove the symlink
		#
		rm -f /etc/resolv.conf

		#
		# Put a file at /etc/resolv.conf with best available content
		#
		# Best is latest dynamic content
		#
		if [ -f /etc/resolvconf/run/resolv.conf ] ; then
			# (Remove "generated by resolvconf" comment which is no longer true)
			grep -sv '^#' /etc/resolvconf/run/resolv.conf > /etc/resolv.conf || :
			rm -f /etc/resolvconf/run/resolv.conf
			# If nothing is left over, remove the file entirely
			[ -s /etc/resolv.conf ] || rm -f /etc/resolv.conf
		fi
		# 
		# Second best is "original" content
		#
		if
			[ ! -f /etc/resolv.conf ] \
			&& [ -f /etc/resolvconf/resolv.conf.d/original ]
		then
			cp -a /etc/resolvconf/resolv.conf.d/original /etc/resolv.conf
		fi
	fi

	rm -f /var/lib/resolvconf/linkified

	report_info "Reboot recommended"
	db_input high resolvconf/reboot-recommended-after-removal || :
	db_go || :

	# Notify packages of the removal of resolvconf
	if [ -d /usr/lib/resolvconf/dpkg-event.d ] ; then
		NOTIFICATION_HOOK_SCRIPTS="$(cd /usr/lib/resolvconf/dpkg-event.d >/dev/null ; run-parts --test .)"
		for SCRPT in $NOTIFICATION_HOOK_SCRIPTS ; do
			PKG="${SCRPT#./}"
			if is_installed "$PKG" ; then
				SCRPT="/usr/lib/resolvconf/dpkg-event.d/$PKG"
				if [ -x "$SCRPT" ] ; then
					"$SCRPT" remove || :
				fi
			fi 
		done
	fi
	;;
  purge)
	#
	# Remove all remaining cruft
	#
	if [ -L /etc/resolvconf/run ] ; then
		rm -f /etc/resolvconf/run
	elif [ -d /etc/resolvconf/run ] ; then
		rm -rf /etc/resolvconf/run
	fi
	rm -f /etc/resolvconf/resolv.conf.d/tail
	rm -f /etc/resolvconf/resolv.conf.d/original
	rm -f /etc/resolvconf/update.d/bind
	rm -f /etc/resolvconf/update.d/bind.dpkg-old
	rm -f /etc/default/resolvconf
	rm -f /etc/dhcp3/dhclient-enter-hooks.d/resolvconf
	rm -f /etc/init.d/resolvconf.dpkg-old
	rm -f /etc/resolv.conf.dpkg-old
	rm -rf "/lib/init/rw/resolvconf" || :
	rm -rf /run/resolvconf || :
	;;
  # disappear|upgrade)
	# Don't do anything on upgrade
	# ;;
  # failed-upgrade)
	# Don't do anything because we don't do anything here (in the postrm) on upgrade
	# ;;
  abort-install)
	rm -f /etc/resolvconf/run/packages-to-notify
	# In the preinst we create directories
	# but there is no immediate need to remove them if there is an error.
	;;
  # abort-upgrade)
	# Don't do anything.
	# In the preinst we create directories
	# but there is no immediate need to remove them if there is an error.
	# ;;

esac

exit 0