Debian Codegraph @

debian/systemd-resolved.postinst

raw
1 #!/bin/sh
2
3 set -e
4
5 _adopt_conffile() {
6 conffile=$1
7 pkg=$2
8
9 [ -f "${conffile}.dpkg-bak" ] || return 0
10
11 md5sum="$(md5sum "${conffile}" | sed -e 's/ .*//')"
12 old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$pkg" | \
13 sed -n -e "\' ${conffile} ' { s/ obsolete$//; s/.* //; p }")"
14 # On new installs, if the policy file was preserved on systemd upgrade
15 # by dpkg-maintscript helper, copy it back if the new file has not been modified yet
16 if [ "$md5sum" = "$old_md5sum" ]; then
17 mv "${conffile}.dpkg-bak" "${conffile}"
18 fi
19 }
20
21
22 if [ "$1" = configure ] && [ -z "$2" ]; then
23 _adopt_conffile "${DPKG_ROOT}/etc/systemd/resolved.conf" systemd-resolved
24 fi
25
26 if [ "$1" = configure ] && dpkg --compare-versions "$2" lt 251.4-2; then
27 if [ "$(readlink "${DPKG_ROOT}/etc/resolv.conf")" != "../run/systemd/resolve/stub-resolv.conf" ] && [ "$(readlink "${DPKG_ROOT}/etc/resolv.conf")" != "/run/systemd/resolve/stub-resolv.conf" ]; then
28 echo "Converting /etc/resolv.conf to a symlink to /run/systemd/resolve/stub-resolv.conf..."
29 mkdir -p "${DPKG_ROOT}/run/systemd/resolve"
30 if [ -f "${DPKG_ROOT}/etc/resolv.conf" ]; then
31 cp "${DPKG_ROOT}/etc/resolv.conf" "${DPKG_ROOT}/run/systemd/resolve/stub-resolv.conf" || echo "Cannot copy /etc/resolv.conf to /run/systemd/resolve/stub-resolv.conf"
32 mv "${DPKG_ROOT}/etc/resolv.conf" "${DPKG_ROOT}/etc/.resolv.conf.systemd-resolved.bak" || echo "Cannot take a backup of /etc/resolv.conf."
33 fi
34 ln -sf ../run/systemd/resolve/stub-resolv.conf "${DPKG_ROOT}/etc/resolv.conf" || echo "Cannot install symlink from /etc/resolv.conf to ../run/systemd/resolve/stub-resolv.conf"
35 fi
36 fi
37
38 #DEBHELPER#