Skip to content

Commit

Permalink
base-files: add preinit ifname detection based on board.json
Browse files Browse the repository at this point in the history
Make use of the existing board.d to autodetect lan ifname in a generic way.

Signed-off-by: Jonas Gorski <[email protected]>
  • Loading branch information
KanjiMonster committed Aug 13, 2016
1 parent 0f1ae84 commit c18edce
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions package/base-files/files/lib/preinit/10_indicate_preinit
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@ preinit_ip_config() {
ip -4 address add $pi_ip/$pi_netmask broadcast $pi_broadcast dev $1
}

preinit_config_board() {
/bin/board_detect /tmp/board.json

[ -f "/tmp/board.json" ] || return

. /usr/share/libubox/jshn.sh

json_init
json_load "$(cat /tmp/board.json)"

json_select network
json_select "lan"
json_get_vars ifname
json_select ..
json_select ..

[ -n "$ifname" ] || return

# only use the first one
ifname=${ifname%% *}

# trim any vlan ids
ifname=${ifname%\.*}

preinit_ip_config $ifname
}

preinit_ip() {
# if the preinit interface isn't specified and ifname is set in
# preinit.arch use that interface
Expand All @@ -18,6 +45,8 @@ preinit_ip() {

if [ -n "$pi_ifname" ]; then
preinit_ip_config $pi_ifname
elif [ -d "/etc/board.d/" ]; then
preinit_config_board
fi
}

Expand Down

0 comments on commit c18edce

Please sign in to comment.