File: preinst

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 (109 lines) | stat: -rwxr-xr-x 3,374 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
#!/bin/sh

set -e

MYNAME=resolvconf.preinst
report() { echo "${MYNAME}: $*" ; }
report_err() { report "Error: $*" >&2 ; }
report_warn() { report "Warning: $*" >&2 ; }
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
}


### Create run-time directories ###
#
# We create the run-time directories here, in the preinst, so that even if
# resolvconf is run before the postinst runs there is nevertheless a place
# for resolvconf to store data.  The latter can occur if resolvconf
# is installed simultaneously with a caching nameserver package whose
# postinst runs resolvconf to add its IP address.
#
case "$1" in
  install|upgrade)
	# Ensure that /etc/resolvconf exists.
	mkdir -p /etc/resolvconf

	if [ -L /etc/resolvconf/run ] ; then
		# Make sure that the symlink is canonicalizable.
		RUN_CANONICALPATH="$(readlink -f /etc/resolvconf/run || :)"
		if [ -z "$RUN_CANONICALPATH" ] ; then
			# It's not canonicalizable
			report_warn "Deleting old symlink /etc/resolvconf/run, the canonical path of whose target could not be determined"
			rm -f /etc/resolvconf/run
		fi
	fi

	# /etc/resolvconf/run is not a non-canonicalizable symlink.

	# Delete /etc/resolvconf/run if it exists but is neither a directory nor a link to one
	if [ -e /etc/resolvconf/run ] && [ ! -d /etc/resolvconf/run ] ; then
		report_warn "Deleting /etc/resolvconf/run which isn't a directory"
		rm -f /etc/resolvconf/run
	fi

	# OK, now /etc/resolvconf/run is either:
	# * nonexistent, or
	# * a dangling but canonicalizable symlink, or
	# * a symlink to a directory, or
	# * a directory.

	# Create subdirectory
	if [ -d /etc/resolvconf/run ] ; then
		# It's a directory or a symlink to one
		[ -d /etc/resolvconf/run/interface ] || mkdir /etc/resolvconf/run/interface
	elif [ -L /etc/resolvconf/run ] ; then
		# It's a dangling but canonicalizable symlink
		mkdir "$RUN_CANONICALPATH" "${RUN_CANONICALPATH}/interface"
	else
		# It's nonexistent.
		# Make directory at the standard location.
		if mkdir -p /run/resolvconf/interface ; then
			ln -s /run/resolvconf /etc/resolvconf/run
		else
			report_err "Could not create run-time directories; aborting"
			exit 1
		fi
	fi
	;;
  # abort-upgrade)
	# Don't do anything because we don't anything in the postrm on upgrade or on failed-upgrade
	# ;;
esac


### Prepare to notify already configured packages of our installation ###

case "$1" in
  install)
	# Create list of packages that might need to be notified of the installation 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 .)"
		PACKAGES_TO_NOTIFY=""
		for SCRPT in $NOTIFICATION_HOOK_SCRIPTS ; do
			PKG="${SCRPT#./}"
			if is_installed "$PKG" ; then
				PACKAGES_TO_NOTIFY="${PACKAGES_TO_NOTIFY:+$PACKAGES_TO_NOTIFY }$PKG"
			fi
		done
		rm -f /etc/resolvconf/run/packages-to-notify
		if [ "$PACKAGES_TO_NOTIFY" ] ; then
			echo "$PACKAGES_TO_NOTIFY" > /etc/resolvconf/run/packages-to-notify
		fi
	fi
	;;
  # upgrade)
	# Don't do anything
	# ;;
  # abort-upgrade)
	# Don't do anything because we don't anything in the postrm on upgrade or on failed-upgrade
	# ;;
esac

#DEBHELPER#

exit 0