meta-sysmocom-bsp/recipes-apps/images/image-static-dns.inc

45 lines
1.7 KiB
PHP

# set the variables DNS_SERVER, DNS_DOMAIN or DNS_SEARCH in your image file
# and require this file afterwards
DNSSERVER = "${@d.getVar('DNS_SERVER', True) or ''}"
DNSDOMAIN = "${@d.getVar('DNS_DOMAIN', True) or ''}"
DNSSEARCH = "${@d.getVar('DNS_SEARCH', True) or ''}"
ROOTFS_POSTPROCESS_COMMAND += "set_static_dns;"
set_static_dns() {
printf "Replacing /etc/resolv.conf\n"
printf "#This default-file was generated by the image-static-dns hook\n \
in the post-image setup.\n\n" > ${IMAGE_ROOTFS}/etc/resolv.conf
if [ -n "${DNSSERVER}" ]; then
printf "setting DNS-server\n"
printf "nameserver %s\n" "${DNSSERVER}" >> ${IMAGE_ROOTFS}/etc/resolv.conf
fi
if [ -n "${DNSDOMAIN}" ]; then
printf "setting DNS-domain\n"
printf "domain %s\n" "${DNSDOMAIN}" >> ${IMAGE_ROOTFS}/etc/resolv.conf
fi
if [ -n "${DNSSEARCH}" ]; then
printf "setting DNS-search\n"
printf "search %s\n" "${DNSSEARCH}" >> ${IMAGE_ROOTFS}/etc/resolv.conf
fi
if [ -w ${IMAGE_ROOTFS}/etc/default/udhcpc ]; then
printf "Configure the installed udhcpc for static DNS\n"
STATIC_DNS_TEXT="# The static-dns configuration was generated by the image-static-dns hook."
sed -i -e "s/^#.*\(STATIC_DNS\).*$/${STATIC_DNS_TEXT}\n\1=\"yes\"/g" ${IMAGE_ROOTFS}/etc/default/udhcpc
else
printf "Configure the not installed udhcpc for static DNS\n"
mkdir -p ${IMAGE_ROOTFS}/etc/default
cat << EOF > ${IMAGE_ROOTFS}/etc/default/udhcpc
#This default-file was generated by the image-static-dns hook,
#in the post-image setup.
#
#When udhcpc is installed one setup needs to be chosen.
STATIC_DNS="yes"
EOF
fi
}