meta-digi-dey: provide DNS configuration at build time

Allows to configure static DNS servers in resolv.conf setting following
variables in your project's config file:

ETH0_STATIC_DNS, ETH1_STATIC_DNS, WLAN0_STATIC_DNS

Those variables accept multiple dns servers (separated by spaces)

https://jira.digi.com/browse/DEL-1266

Signed-off-by: Javier Viguera <javier.viguera@digi.com>
This commit is contained in:
Javier Viguera 2014-11-25 11:02:07 +01:00
parent 4301bfc736
commit e1d95f25cc
5 changed files with 54 additions and 10 deletions

View File

@ -4,3 +4,4 @@ iface eth0 inet static
address ##ETH0_STATIC_IP##
netmask ##ETH0_STATIC_NETMASK##
gateway ##ETH0_STATIC_GATEWAY##
dns-nameservers ##ETH0_STATIC_DNS##

View File

@ -3,3 +3,4 @@ auto eth1
iface eth1 inet static
address ##ETH1_STATIC_IP##
netmask ##ETH1_STATIC_NETMASK##
dns-nameservers ##ETH1_STATIC_DNS##

View File

@ -3,5 +3,6 @@ auto wlan0
iface wlan0 inet static
address ##WLAN0_STATIC_IP##
netmask ##WLAN0_STATIC_NETMASK##
dns-nameservers ##WLAN0_STATIC_DNS##
wpa-driver ##WPA_DRIVER##
wpa-conf /etc/wpa_supplicant.conf

View File

@ -0,0 +1,30 @@
#!/bin/sh
#===============================================================================
#
# resolv
#
# Copyright (C) 2014 by Digi International Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
#
# !Description: Configure static DNS servers with ifup
#
#===============================================================================
# Only for static method
[ "${METHOD}" != "static" ] && exit 0
RESOLVCONF="$(readlink /etc/resolv.conf)"
NAMESERVERS=""
for NS in ${IF_DNS_NAMESERVER} ${IF_DNS_NAMESERVERS}; do
NAMESERVERS="${NAMESERVERS:+${NAMESERVERS}\n}nameserver ${NS}"
done
if [ -n "${RESOLVCONF}" -a -n "${NAMESERVERS}" ]; then
printf "${NAMESERVERS}\n" > "${RESOLVCONF}"
fi

View File

@ -8,7 +8,9 @@ SRC_URI_append = " \
file://interfaces.eth1.static \
file://interfaces.eth1.dhcp \
file://interfaces.wlan0.static \
file://interfaces.wlan0.dhcp"
file://interfaces.wlan0.dhcp \
file://resolv \
"
SRC_URI_append_mx5 = " file://ifup"
@ -20,16 +22,25 @@ do_install_append() {
[ -n "${HAVE_EXT_ETH}" ] && cat ${WORKDIR}/interfaces.eth1.${ETH1_MODE} >> ${D}${sysconfdir}/network/interfaces
[ -n "${HAVE_WIFI}" ] && cat ${WORKDIR}/interfaces.wlan0.${WLAN0_MODE} >> ${D}${sysconfdir}/network/interfaces
# Install DNS servers handler but remove DNS config lines if no DNS specified
install -m 0755 ${WORKDIR}/resolv ${D}${sysconfdir}/network/if-up.d/resolv
[ -z "${ETH0_STATIC_DNS}" ] && sed -i -e "/##ETH0_STATIC_DNS##/d" ${D}${sysconfdir}/network/interfaces
[ -z "${ETH1_STATIC_DNS}" ] && sed -i -e "/##ETH1_STATIC_DNS##/d" ${D}${sysconfdir}/network/interfaces
[ -z "${WLAN0_STATIC_DNS}" ] && sed -i -e "/##WLAN0_STATIC_DNS##/d" ${D}${sysconfdir}/network/interfaces
# Replace interface parameters
sed -i -e 's,##ETH0_STATIC_IP##,${ETH0_STATIC_IP},g' ${D}${sysconfdir}/network/interfaces
sed -i -e 's,##ETH0_STATIC_NETMASK##,${ETH0_STATIC_NETMASK},g' ${D}${sysconfdir}/network/interfaces
sed -i -e 's,##ETH0_STATIC_GATEWAY##,${ETH0_STATIC_GATEWAY},g' ${D}${sysconfdir}/network/interfaces
sed -i -e 's,##ETH1_STATIC_IP##,${ETH1_STATIC_IP},g' ${D}${sysconfdir}/network/interfaces
sed -i -e 's,##ETH1_STATIC_NETMASK##,${ETH1_STATIC_NETMASK},g' ${D}${sysconfdir}/network/interfaces
sed -i -e 's,##ETH1_STATIC_GATEWAY##,${ETH1_STATIC_GATEWAY},g' ${D}${sysconfdir}/network/interfaces
sed -i -e 's,##WLAN0_STATIC_IP##,${WLAN0_STATIC_IP},g' ${D}${sysconfdir}/network/interfaces
sed -i -e 's,##WLAN0_STATIC_NETMASK##,${WLAN0_STATIC_NETMASK},g' ${D}${sysconfdir}/network/interfaces
sed -i -e 's,##WLAN0_STATIC_GATEWAY##,${WLAN0_STATIC_GATEWAY},g' ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##ETH0_STATIC_IP##,${ETH0_STATIC_IP},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##ETH0_STATIC_NETMASK##,${ETH0_STATIC_NETMASK},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##ETH0_STATIC_GATEWAY##,${ETH0_STATIC_GATEWAY},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##ETH0_STATIC_DNS##,${ETH0_STATIC_DNS},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##ETH1_STATIC_IP##,${ETH1_STATIC_IP},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##ETH1_STATIC_NETMASK##,${ETH1_STATIC_NETMASK},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##ETH1_STATIC_GATEWAY##,${ETH1_STATIC_GATEWAY},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##ETH1_STATIC_DNS##,${ETH1_STATIC_DNS},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##WLAN0_STATIC_IP##,${WLAN0_STATIC_IP},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##WLAN0_STATIC_NETMASK##,${WLAN0_STATIC_NETMASK},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##WLAN0_STATIC_GATEWAY##,${WLAN0_STATIC_GATEWAY},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##WLAN0_STATIC_DNS##,${WLAN0_STATIC_DNS},g" ${D}${sysconfdir}/network/interfaces
sed -i -e "s,##WPA_DRIVER##,${WPA_DRIVER},g" ${D}${sysconfdir}/network/interfaces
}