netcup: dns fixes

This commit is contained in:
Girish Ramakrishnan
2024-05-04 17:36:26 +02:00
parent 1728756dc4
commit 6681f2e5c8
3 changed files with 27 additions and 6 deletions

View File

@@ -149,7 +149,7 @@ printf "**********************************************************************\n
EOF
chmod +x /etc/update-motd.d/91-cloudron-install-in-progress
# workaround netcup setting immutable bit. can be removed in 8.0
# workaround netcup setting immutable bit. required for installation pre 8.0
if lsattr -l /etc/resolv.conf 2>/dev/null | grep -q Immutable; then
chattr -i /etc/resolv.conf
fi

View File

@@ -25,10 +25,17 @@ apt-get -o Dpkg::Options::="--force-confdef" update -y
apt-get -o Dpkg::Options::="--force-confdef" upgrade -y
apt-mark unhold grub* >/dev/null
# workaround netcup setting immutable bit. can be removed in 8.0
if lsattr -l /etc/resolv.conf 2>/dev/null | grep -q Immutable; then
echo "==> Fixing up /etc/resolv.conf"
chattr -i /etc/resolv.conf
vendor=$(cat /sys/devices/virtual/dmi/id/sys_vendor || true)
if [[ "${vendor}" == "netcup" && ! -L /etc/resolv.conf ]]; then
echo "==> Fix netcup DNS setup"
nameservers=$(sed -ne 's/nameserver \(.*\)/"\1"/p' /etc/resolv.conf | paste -sd "," -) # json array
if lsattr -l /etc/resolv.conf 2>/dev/null | grep -q Immutable; then
chattr -i /etc/resolv.conf # this code is also in cloudron-setup. that code can be removed much after 8.0
fi
ln -frs /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
netplan set --origin-hint 50-cloud-init "ethernets.eth0.nameservers.addresses=[${nameservers}]"
netplan apply # generates /run/systemd/resolve/resolv.conf
systemctl restart systemd-resolved
fi
echo "==> Installing required packages"

View File

@@ -80,14 +80,28 @@ fi
# switch over to resolved and uninstall resolvconf
if dpkg -s resolvconf 2>/dev/null >/dev/null; then
vendor=$(cat /sys/devices/virtual/dmi/id/sys_vendor || true)
prepare_apt_once # do this first before DNS goes away intermittently
log "disabling unbound"
systemctl disable unbound || true
systemctl stop unbound || true
log "enabling systemd-resolved"
systemctl enable --now systemd-resolved
log "removing resolvconf"
prepare_apt_once
[[ "${vendor}" == "netcup" && -f /etc/resolvconf/resolv.conf.d/original ]] && cp /etc/resolvconf/resolv.conf.d/original /tmp/resolv.conf.original # stash before purging
apt -y --purge remove resolvconf # purge required for dpkg -s to return error code
if [[ "${vendor}" == "netcup" && -f /tmp/resolv.conf.original ]]; then
log "Fix netcup DNS setup"
nameservers=$(sed -ne 's/nameserver \(.*\)/"\1"/p' /tmp/resolv.conf.original | paste -sd "," -) # json array
netplan set --origin-hint 50-cloud-init "ethernets.eth0.nameservers.addresses=[${nameservers}]"
netplan apply # generates /run/systemd/resolve/resolv.conf
systemctl restart systemd-resolved
fi
fi
# https://docs.docker.com/engine/installation/linux/ubuntulinux/