From 4204309872da5cb401cbb2729d9e2d4869a87f42 Mon Sep 17 00:00:00 2001 From: takeshi_hoshina Date: Thu, 22 Oct 2020 14:58:56 +0900 Subject: agl-basesystem 0.1 --- .../recipes-core/initramfs-netboot/files/init.sh | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'meta-agl/meta-netboot/recipes-core/initramfs-netboot/files/init.sh') diff --git a/meta-agl/meta-netboot/recipes-core/initramfs-netboot/files/init.sh b/meta-agl/meta-netboot/recipes-core/initramfs-netboot/files/init.sh index 7b8fbb51..50d62472 100644 --- a/meta-agl/meta-netboot/recipes-core/initramfs-netboot/files/init.sh +++ b/meta-agl/meta-netboot/recipes-core/initramfs-netboot/files/init.sh @@ -57,6 +57,29 @@ check_debug() { esac } +find_active_interface() { + [[ ! -d /sys/class/net ]] && { log_error "find_active_interface: /sys/class/net doesn't exist"; return 2; } + local iface + for x in $(ls -d /sys/class/net/* 2>/dev/null); do + iface=$(basename $x) + # find interfaces with: + # - type == 1 (ethernet) + # - not wireless + # - with state up + + [[ $(cat $x/type) != 1 ]] && continue + [[ -d $x/wireless ]] && continue + [[ $(cat $x/operstate) != "up" ]] && continue + + log_info "find_active_interface: first active interface is $iface" + echo $iface + return 0 + done + + log_error "Unable to find any active network interface." + return 1 +} + # ------------------------------------------- export PATH=/sbin:/usr/sbin:/bin:/usr/bin @@ -131,9 +154,12 @@ pivot_root . boot/initramfs || bail_out "pivot_root failed." # workaround for connman (avoid bringing down the network interface used for booting, disable DNS proxy) if [[ -f /lib/systemd/system/connman.service ]]; then - log_info "Adjusting Connman configuration" - iface=$(ip -o link show up | tr ':' ' ' | awk '{print $2}' | grep -v -e "^lo$" | head -1) - sed -i "s|connmand -n\$|connmand -r -n -I $iface|g" /lib/systemd/system/connman.service + newopts="-r -n" + iface=$(find_active_interface) + [[ -n "$iface" ]] && newopts="$newopts -I $iface" + + log_info "Adjusting Connman command line. Will be: 'connmand $newopts'" + sed -i "s|connmand -n\$|connmand $newopts|g" /lib/systemd/system/connman.service fi # also use /proc/net/pnp to generate /etc/resolv.conf -- cgit 1.2.3-korg