init-ifupdown: rework whole package
Simplify the package for maintainability and fix some minor things. https://jira.digi.com/browse/DEL-818 Signed-off-by: Javier Viguera <javier.viguera@digi.com>
This commit is contained in:
parent
328a6cdb5e
commit
a137f4f190
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh -l
|
#!/bin/sh
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
#
|
#
|
||||||
# ifup
|
# ifup
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
# the Free Software Foundation.
|
# the Free Software Foundation.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# !Description: Set network interfaces MAC addresses.
|
# !Description: Set network interfaces MAC addresses on i.MX5X
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
|
|
@ -21,32 +21,13 @@ set -e
|
||||||
[ "${METHOD}" = "loopback" ] && exit 0
|
[ "${METHOD}" = "loopback" ] && exit 0
|
||||||
|
|
||||||
# Do nothing if interface does not exist
|
# Do nothing if interface does not exist
|
||||||
[ ! -h /sys/class/net/${IFACE} ] && exit 0
|
[ -d "/sys/class/net/${IFACE}" ] || exit 0
|
||||||
|
|
||||||
if [ -h /sys/class/net/eth0 ]; then
|
driver="$(readlink -f -n /sys/class/net/${IFACE} | sed 's,/sys/devices/platform/\(.\{3\}\).*,\1,g')"
|
||||||
driver="$(readlink -f -n /sys/class/net/eth0 | sed 's,\/,\n,g' | awk '/fec/ {print}')"
|
|
||||||
case ${driver} in
|
|
||||||
fec.*)
|
|
||||||
macaddr=`cat /proc/cmdline | sed 's,\s,\n,g' | awk '/ethaddr1/ {print}' | sed 's,ethaddr1=,,g'`
|
|
||||||
;;
|
|
||||||
sms.*)
|
|
||||||
macaddr=`cat /proc/cmdline | sed 's,\s,\n,g' | awk '/ethaddr3/ {print}' | sed 's,ethaddr3=,,g'`
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
if [ "${macaddr}" ]; then
|
|
||||||
if /sbin/ifconfig eth0 | grep -qs UP; then
|
|
||||||
/sbin/ifconfig eth0 hw ether ${macaddr}
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -h /sys/class/net/eth1 ]; then
|
case "${IFACE}:${driver}" in
|
||||||
macaddr=`cat /proc/cmdline | sed 's,\s,\n,g' | awk '/ethaddr3/ {print}' | sed 's,ethaddr3=,,g'`
|
eth1: | *:sms)
|
||||||
if [ "${macaddr}" ]; then
|
macaddr="$(sed -ne 's,^.*ethaddr3=\([^[:blank:]]\+\)[:blank:]*.*,\1,g;T;p' /proc/cmdline)"
|
||||||
if /sbin/ifconfig eth1 | grep -qs UP; then
|
esac
|
||||||
/sbin/ifconfig eth1 hw ether ${macaddr}
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
[ -n "${macaddr}" ] && ifconfig ${IFACE} hw ether ${macaddr} up
|
||||||
|
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
#!/bin/sh -e
|
|
||||||
### BEGIN INIT INFO
|
|
||||||
# Provides: networking
|
|
||||||
# Required-Start: mountvirtfs $local_fs
|
|
||||||
# Required-Stop: $local_fs
|
|
||||||
# Should-Start: ifupdown
|
|
||||||
# Should-Stop: ifupdown
|
|
||||||
# Default-Start: S
|
|
||||||
# Default-Stop: 0 6
|
|
||||||
# Short-Description: Raise network interfaces.
|
|
||||||
### END INIT INFO
|
|
||||||
|
|
||||||
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
|
|
||||||
|
|
||||||
[ -x /sbin/ifup ] || exit 0
|
|
||||||
|
|
||||||
check_network_file_systems() {
|
|
||||||
[ -e /proc/mounts ] || return 0
|
|
||||||
|
|
||||||
if [ -e /etc/iscsi/iscsi.initramfs ]; then
|
|
||||||
echo "not deconfiguring network interfaces: iSCSI root is mounted."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec 9<&0 < /proc/mounts
|
|
||||||
while read DEV MTPT FSTYPE REST; do
|
|
||||||
case $DEV in
|
|
||||||
/dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
|
|
||||||
echo "not deconfiguring network interfaces: network devices still mounted."
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
case $FSTYPE in
|
|
||||||
nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|pvfs|pvfs2|fuse.httpfs|fuse.curlftpfs)
|
|
||||||
echo "not deconfiguring network interfaces: network file systems still mounted."
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
exec 0<&9 9<&-
|
|
||||||
}
|
|
||||||
|
|
||||||
check_network_swap() {
|
|
||||||
[ -e /proc/swaps ] || return 0
|
|
||||||
|
|
||||||
exec 9<&0 < /proc/swaps
|
|
||||||
while read DEV MTPT FSTYPE REST; do
|
|
||||||
case $DEV in
|
|
||||||
/dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
|
|
||||||
echo "not deconfiguring network interfaces: network swap still mounted."
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
exec 0<&9 9<&-
|
|
||||||
}
|
|
||||||
|
|
||||||
start_on_boot() {
|
|
||||||
echo -n "Configuring network interfaces... "
|
|
||||||
ifup -a
|
|
||||||
echo "done."
|
|
||||||
}
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
start)
|
|
||||||
start_on_boot &
|
|
||||||
;;
|
|
||||||
|
|
||||||
stop)
|
|
||||||
check_network_file_systems
|
|
||||||
check_network_swap
|
|
||||||
|
|
||||||
echo -n "Deconfiguring network interfaces... "
|
|
||||||
ifdown -a
|
|
||||||
echo "done."
|
|
||||||
;;
|
|
||||||
|
|
||||||
force-reload|restart)
|
|
||||||
echo "Running $0 $1 is deprecated because it may not enable again some interfaces"
|
|
||||||
echo "Reconfiguring network interfaces... "
|
|
||||||
ifdown -a || true
|
|
||||||
ifup -a
|
|
||||||
echo "done."
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "Usage: /etc/init.d/networking {start|stop}"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
|
|
@ -1,3 +1,36 @@
|
||||||
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
|
## The loopback interface
|
||||||
|
auto lo
|
||||||
|
iface lo inet loopback
|
||||||
|
|
||||||
# Dummy file - will be autogenerated in target.
|
auto eth0
|
||||||
|
## eth0 static config
|
||||||
|
iface eth0 inet static
|
||||||
|
address 192.168.42.30
|
||||||
|
netmask 255.255.255.0
|
||||||
|
gateway 192.168.42.1
|
||||||
|
|
||||||
|
## eth0 dhcp config
|
||||||
|
#iface eth0 inet dhcp
|
||||||
|
# udhcpc_opts -b
|
||||||
|
|
||||||
|
#auto eth1
|
||||||
|
## eth1 static config
|
||||||
|
iface eth1 inet static
|
||||||
|
address 192.168.44.30
|
||||||
|
netmask 255.255.255.0
|
||||||
|
|
||||||
|
## eth1 dhcp config
|
||||||
|
#iface eth1 inet dhcp
|
||||||
|
# udhcpc_opts -b
|
||||||
|
|
||||||
|
#auto wlan0
|
||||||
|
## wlan0 static config
|
||||||
|
iface wlan0 inet static
|
||||||
|
address 192.168.43.30
|
||||||
|
netmask 255.255.255.0
|
||||||
|
wpa-driver ##WPA_DRIVER##
|
||||||
|
wpa-conf /etc/wpa_supplicant.conf
|
||||||
|
|
||||||
|
## wlan0 dhcp config
|
||||||
|
#iface wlan0 inet dhcp
|
||||||
|
# udhcpc_opts -b
|
||||||
|
|
|
||||||
|
|
@ -5,100 +5,27 @@ PR_append = "+${DISTRO}"
|
||||||
|
|
||||||
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:"
|
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:"
|
||||||
|
|
||||||
DEPENDS = "virtual/kernel"
|
SRC_URI_append_mx5 = " file://ifup"
|
||||||
|
|
||||||
SRC_URI += "file://ifup"
|
|
||||||
|
|
||||||
WPA_DRIVER ?= "wext"
|
WPA_DRIVER ?= "wext"
|
||||||
|
|
||||||
do_install_append(){
|
do_install_append() {
|
||||||
|
# Enable or disable second ethernet interface
|
||||||
|
if [ -n "${HAVE_EXT_ETH}" ]; then
|
||||||
|
sed -i -e '/^.*auto eth1.*/cauto eth1' ${D}${sysconfdir}/network/interfaces
|
||||||
|
else
|
||||||
|
sed -i -e '/^.*auto eth1.*/c#auto eth1' ${D}${sysconfdir}/network/interfaces
|
||||||
|
fi
|
||||||
|
# Enable or disable wifi interface
|
||||||
|
if [ -n "${HAVE_WIFI}" ]; then
|
||||||
|
sed -i -e '/^.*auto wlan0.*/cauto wlan0' ${D}${sysconfdir}/network/interfaces
|
||||||
|
else
|
||||||
|
sed -i -e '/^.*auto wlan0.*/c#auto wlan0' ${D}${sysconfdir}/network/interfaces
|
||||||
|
fi
|
||||||
|
# Configure wpa_supplicant driver
|
||||||
|
sed -i -e "s,##WPA_DRIVER##,${WPA_DRIVER},g" ${D}${sysconfdir}/network/interfaces
|
||||||
|
}
|
||||||
|
|
||||||
|
do_install_append_mx5() {
|
||||||
install -m 0755 ${WORKDIR}/ifup ${D}${sysconfdir}/network/if-up.d
|
install -m 0755 ${WORKDIR}/ifup ${D}${sysconfdir}/network/if-up.d
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg_postinst_${PN} () {
|
|
||||||
#!/bin/sh
|
|
||||||
INTERFACES_PATH=$D/etc/network/interfaces
|
|
||||||
if test "x$D" != "x"; then
|
|
||||||
KERNEL_CONFIG_PATH=${STAGING_KERNEL_DIR}/.config
|
|
||||||
else
|
|
||||||
KERNEL_CONFIG_PATH=/boot/config*
|
|
||||||
fi
|
|
||||||
|
|
||||||
> ${INTERFACES_PATH}
|
|
||||||
|
|
||||||
/bin/grep -q "CONFIG_BLK_DEV_LOOP=" ${KERNEL_CONFIG_PATH}
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
cat << EOF >> ${INTERFACES_PATH}
|
|
||||||
# The loopback interface
|
|
||||||
auto lo
|
|
||||||
iface lo inet loopback
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
/bin/grep -q "CONFIG_FEC=" ${KERNEL_CONFIG_PATH}
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
# Primary wired interface
|
|
||||||
cat << EOF >> ${INTERFACES_PATH}
|
|
||||||
auto eth0
|
|
||||||
# Use for dhcp
|
|
||||||
# iface eth0 inet dhcp
|
|
||||||
iface eth0 inet static
|
|
||||||
address 192.168.42.30
|
|
||||||
netmask 255.255.255.0
|
|
||||||
network 192.168.42.0
|
|
||||||
gateway 192.168.42.1
|
|
||||||
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Secondary wired interface on MXC platforms
|
|
||||||
/bin/grep -q "CONFIG_SMSC911X=" ${KERNEL_CONFIG_PATH}
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
cat << EOF >> ${INTERFACES_PATH}
|
|
||||||
auto eth1
|
|
||||||
# Use for dhcp
|
|
||||||
# iface eth1 inet dhcp
|
|
||||||
iface eth1 inet static
|
|
||||||
address 192.168.44.30
|
|
||||||
netmask 255.255.255.0
|
|
||||||
network 192.168.44.0
|
|
||||||
gateway 192.168.44.1
|
|
||||||
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Secondary wired interface on MXS platforms
|
|
||||||
/bin/grep -q "CONFIG_CCARDIMX28_ENET1=" ${KERNEL_CONFIG_PATH}
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
cat << EOF >> ${INTERFACES_PATH}
|
|
||||||
auto eth1
|
|
||||||
# Use for dhcp
|
|
||||||
# iface eth1 inet dhcp
|
|
||||||
iface eth1 inet static
|
|
||||||
address 192.168.44.30
|
|
||||||
netmask 255.255.255.0
|
|
||||||
network 192.168.44.0
|
|
||||||
gateway 192.168.44.1
|
|
||||||
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Wireless interface
|
|
||||||
/bin/grep -q "CONFIG_WIRELESS=" ${KERNEL_CONFIG_PATH}
|
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
cat << EOF >> ${INTERFACES_PATH}
|
|
||||||
auto wlan0
|
|
||||||
# Use for dhcp
|
|
||||||
# iface wlan0 inet dhcp
|
|
||||||
iface wlan0 inet static
|
|
||||||
address 192.168.43.30
|
|
||||||
netmask 255.255.255.0
|
|
||||||
network 192.168.43.0
|
|
||||||
wireless_mode managed
|
|
||||||
wireless_essid any
|
|
||||||
wpa-driver ${WPA_DRIVER}
|
|
||||||
wpa-conf /etc/wpa_supplicant.conf
|
|
||||||
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue