Skip to content

Commit

Permalink
fix: fix handling of resolv.conf file
Browse files Browse the repository at this point in the history
Includes changes if resolv.conf is a symbolic link

Mostly affected are armbian based images

Signed-off-by: Stephan Wendel <me@stephanwe.de>
  • Loading branch information
KwadFan authored and guysoft committed Aug 23, 2024
1 parent 02bb0ec commit 4526f28
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/modules/base/end_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ if [ "${BASE_DISTRO}" == "ubuntu" ];then
echo "127.0.0.1 ${BASE_OVERRIDE_HOSTNAME}" > /etc/hosts
fi

# restore resolve.conf
if [ -f /.resolvconf_link ]; then
resolvconf_target="$(cat /.resolvconf_link)"
ln -sf "${resolvconf_target}" /etc/resolv.conf 2>/dev/null
rm -f /.resolvconf_link
else
if [ -f /etc/resolv.conf.orig ]; then
mv /etc/resolv.conf.orig /etc/resolv.conf
fi
fi

#cleanup
if [ "${BASE_APT_CLEAN}" = "yes" ]; then
apt-get clean
Expand Down
35 changes: 27 additions & 8 deletions src/modules/base/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ if [ -n "${BASE_APT_MIRROR}" ]; then
mv /tmp/filename.tmp /etc/apt/sources.list
fi

if [ "${BASE_DISTRO}" == "ubuntu" ]; then
unpack /filesystem/ubuntu / root

mv /etc/resolv.conf /etc/resolv.conf.orig || true
function generate_resolvconf {
if [ -z "${BASE_USE_ALT_DNS}" ]; then
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
echo "nameserver 1.1.1.1" >> /etc/resolv.conf
touch /etc/resolv.conf
for dns in 8.8.8.8 8.8.4.4 1.1.1.1; do
echo "nameserver ${dns}" >> /etc/resolv.conf
done
else
touch /etc/resolv.conf
for dns in ${BASE_USE_ALT_DNS}; do
echo "nameserver ${dns}" >> /etc/resolv.conf
done
fi
}

if [ "${BASE_DISTRO}" == "ubuntu" ]; then
unpack /filesystem/ubuntu / root

mv /etc/resolv.conf /etc/resolv.conf.orig || true

generate_resolvconf


apt-get update --allow-releaseinfo-change
apt-get install -y net-tools wireless-tools dhcpcd5
if [ $( is_in_apt policykit-1 ) -eq 1 ]; then
Expand All @@ -48,6 +53,20 @@ if [ "${BASE_DISTRO}" == "ubuntu" ]; then

fi

if [ "${BASE_DISTRO}" != "ubuntu" ]; then
# Armbian > 24.5 workaround
if [ -h /etc/resolv.conf ]; then
link_target="$(ls -l /etc/resolv.conf | cut -f2 -d">" | sed 's/^[[:space:]]//')"
echo "${link_target}" > /.resolvconf_link
rm -f /etc/resolv.conf
else
mv /etc/resolv.conf /etc/resolv.conf.orig || true
fi

generate_resolvconf

fi

#Helper Function for create_userconf
function get_os_version {
local os_version
Expand Down

0 comments on commit 4526f28

Please sign in to comment.