From ab195cc90f95277f7f55dfbafe239f15de0f52a5 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Fri, 27 Jun 2025 16:02:38 +0200 Subject: [PATCH] allow predictable network interfaces on dual-eth-raspi: - eth0 -> end0 - eth1 -> enx... --- cfg/linse-rpi12.cfg | 9 +++++++++ install.py | 30 +++++++++++++++++++----------- sethostname.sh | 6 +++++- to_system/etc/profile.d/welcome.sh | 7 ++++++- utils.py | 2 +- 5 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 cfg/linse-rpi12.cfg diff --git a/cfg/linse-rpi12.cfg b/cfg/linse-rpi12.cfg new file mode 100644 index 0000000..36fdaaf --- /dev/null +++ b/cfg/linse-rpi12.cfg @@ -0,0 +1,9 @@ +; please refer to README.md for help + +[BOX] +type=dual-eth-rpi +MAC=d8:3a:dd:51:2d:56 + +[NETWORK] +end0=wan +enx00e04c680155=192.168.1.1 diff --git a/install.py b/install.py index f99ccb8..23a51c5 100755 --- a/install.py +++ b/install.py @@ -60,8 +60,8 @@ TEMPLATES = {} TEMPLATES['bare-apu'] = f"""{COMMENT} [BOX] -type=%s -MAC=%s +type=%(typ)s +MAC=%(mac)s [NETWORK] eth0=wan @@ -76,8 +76,8 @@ eth3=192.168.127.254 TEMPLATES['control-box'] = f"""{COMMENT} [BOX] -type=%s -MAC=%s +type=%(typ)s +MAC=%(mac)s [NETWORK] eth0=wan @@ -94,19 +94,19 @@ line2=ADDR TEMPLATES['dual-eth-rpi'] = f"""{COMMENT} [BOX] -type=%s -MAC=%s +type=%(typ)s +MAC=%(mac)s [NETWORK] -eth0=wan -eth1=192.168.1.1 +end0=wan +%(mac2)s=192.168.1.1 """ GENERIC_TEMPLATE = f"""{COMMENT} [BOX] -type=%s -MAC=%s +type=%(typ)s +MAC=%(mac)s """ DHCP_HEADER = """ @@ -550,6 +550,7 @@ def handle_config(): print('box type:', box.typ, ' mac addr:', box.macaddr) print('---') else: + template_args = {'mac': box.macaddr} if box.typ == 'apu': # determine if display is present disp = serial.Serial('/dev/ttyS1', baudrate=115200, timeout=1) @@ -562,6 +563,11 @@ def handle_config(): elif box.typ == 'cm4': box.typ = 'dual-eth-rpi' print('This is a cm4, so guess its a dual-eth-rpi - please check type in created cfg file') + template_args['mac2'] = 'enx?' + for addr in box.network_interfaces: + if addr.startswith('enx'): + template_args['mac2'] = addr + print(template_args) elif box.typ == 'cm3': print('This is a cm3 so guess its a ionopimax - please check type in created cfg file') box.typ = 'ionopimax' @@ -572,7 +578,8 @@ def handle_config(): if template is None: box.typ = box.typ or 'unknown-box' template = GENERIC_TEMPLATE - template = template % (box.typ, box.macaddr) + template_args['typ'] = box.typ + template = template % template_args print('no cfg file found for this', box.typ, f'with mac address {box.macaddr} (hostname={box.hostname})') @@ -740,6 +747,7 @@ else: doit = True handle_config() walk(Do()) + unix_cmd(f'rm -f {TOOLS / "current"}') with open(TOOLS / 'current', 'w') as f: f.write(result) elif 'more'.startswith(answer.lower()): diff --git a/sethostname.sh b/sethostname.sh index 4dd7118..7bc974d 100644 --- a/sethostname.sh +++ b/sethostname.sh @@ -1,4 +1,8 @@ -ETHNAME=$(cat /sys/class/net/eth0/address) +if [[ -f /sys/class/net/eth0/address ]]; then + ETHNAME=$(cat /sys/class/net/eth0/address) +else + ETHNAME=$(cat /sys/class/net/end0/address) +fi FOUND=($(grep -l -r MAC=$ETHNAME /home/l_samenv/boxtools/cfg)) if [ -z "$FOUND" ]; then BOXID=${ETHNAME//:/} diff --git a/to_system/etc/profile.d/welcome.sh b/to_system/etc/profile.d/welcome.sh index c78468b..021c1a2 100755 --- a/to_system/etc/profile.d/welcome.sh +++ b/to_system/etc/profile.d/welcome.sh @@ -1,7 +1,12 @@ export EDITOR=nano echo "-----------------------------------------------------" echo "Welcome to $HOSTNAME $(hostname -I)" -echo "ethernet addr $(cat /sys/class/net/eth0/address)" +if [[ -f /sys/class/net/eth0/address ]]; then + ETHNAME=$(cat /sys/class/net/eth0/address) +else + ETHNAME=$(cat /sys/class/net/end0/address) +fi +echo "ethernet addr $ETHNAME" function service_status () { for name in $@; do \ enabled=$(systemctl is-enabled ${name} 2> /dev/null) && \ diff --git a/utils.py b/utils.py index dd08002..f3c4e96 100644 --- a/utils.py +++ b/utils.py @@ -95,7 +95,7 @@ class BoxInfo: ifname = f'eth{int(ifname[3]) - 1}' with open(ifdev) as f: self.network_interfaces[ifname] = addr = f.read().strip().lower() - if ifname in ('eth0', 'enp1s0'): + if ifname in ('eth0', 'enp1s0', 'end0'): macaddr = addr self.main_if = ifname self.macaddr = macaddr