allow predictable network interfaces

on dual-eth-raspi:
- eth0 -> end0
- eth1 -> enx...
This commit is contained in:
2025-06-27 16:02:38 +02:00
committed by l_samenv
parent fe95372127
commit ab195cc90f
5 changed files with 40 additions and 14 deletions

9
cfg/linse-rpi12.cfg Normal file
View File

@ -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

View File

@ -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()):

View File

@ -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//:/}

View File

@ -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) && \

View File

@ -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