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} TEMPLATES['bare-apu'] = f"""{COMMENT}
[BOX] [BOX]
type=%s type=%(typ)s
MAC=%s MAC=%(mac)s
[NETWORK] [NETWORK]
eth0=wan eth0=wan
@ -76,8 +76,8 @@ eth3=192.168.127.254
TEMPLATES['control-box'] = f"""{COMMENT} TEMPLATES['control-box'] = f"""{COMMENT}
[BOX] [BOX]
type=%s type=%(typ)s
MAC=%s MAC=%(mac)s
[NETWORK] [NETWORK]
eth0=wan eth0=wan
@ -94,19 +94,19 @@ line2=ADDR
TEMPLATES['dual-eth-rpi'] = f"""{COMMENT} TEMPLATES['dual-eth-rpi'] = f"""{COMMENT}
[BOX] [BOX]
type=%s type=%(typ)s
MAC=%s MAC=%(mac)s
[NETWORK] [NETWORK]
eth0=wan end0=wan
eth1=192.168.1.1 %(mac2)s=192.168.1.1
""" """
GENERIC_TEMPLATE = f"""{COMMENT} GENERIC_TEMPLATE = f"""{COMMENT}
[BOX] [BOX]
type=%s type=%(typ)s
MAC=%s MAC=%(mac)s
""" """
DHCP_HEADER = """ DHCP_HEADER = """
@ -550,6 +550,7 @@ def handle_config():
print('box type:', box.typ, ' mac addr:', box.macaddr) print('box type:', box.typ, ' mac addr:', box.macaddr)
print('---') print('---')
else: else:
template_args = {'mac': box.macaddr}
if box.typ == 'apu': if box.typ == 'apu':
# determine if display is present # determine if display is present
disp = serial.Serial('/dev/ttyS1', baudrate=115200, timeout=1) disp = serial.Serial('/dev/ttyS1', baudrate=115200, timeout=1)
@ -562,6 +563,11 @@ def handle_config():
elif box.typ == 'cm4': elif box.typ == 'cm4':
box.typ = 'dual-eth-rpi' box.typ = 'dual-eth-rpi'
print('This is a cm4, so guess its a dual-eth-rpi - please check type in created cfg file') 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': elif box.typ == 'cm3':
print('This is a cm3 so guess its a ionopimax - please check type in created cfg file') print('This is a cm3 so guess its a ionopimax - please check type in created cfg file')
box.typ = 'ionopimax' box.typ = 'ionopimax'
@ -572,7 +578,8 @@ def handle_config():
if template is None: if template is None:
box.typ = box.typ or 'unknown-box' box.typ = box.typ or 'unknown-box'
template = GENERIC_TEMPLATE 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, print('no cfg file found for this', box.typ,
f'with mac address {box.macaddr} (hostname={box.hostname})') f'with mac address {box.macaddr} (hostname={box.hostname})')
@ -740,6 +747,7 @@ else:
doit = True doit = True
handle_config() handle_config()
walk(Do()) walk(Do())
unix_cmd(f'rm -f {TOOLS / "current"}')
with open(TOOLS / 'current', 'w') as f: with open(TOOLS / 'current', 'w') as f:
f.write(result) f.write(result)
elif 'more'.startswith(answer.lower()): 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)) FOUND=($(grep -l -r MAC=$ETHNAME /home/l_samenv/boxtools/cfg))
if [ -z "$FOUND" ]; then if [ -z "$FOUND" ]; then
BOXID=${ETHNAME//:/} BOXID=${ETHNAME//:/}

View File

@ -1,7 +1,12 @@
export EDITOR=nano export EDITOR=nano
echo "-----------------------------------------------------" echo "-----------------------------------------------------"
echo "Welcome to $HOSTNAME $(hostname -I)" 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 () { function service_status () {
for name in $@; do \ for name in $@; do \
enabled=$(systemctl is-enabled ${name} 2> /dev/null) && \ enabled=$(systemctl is-enabled ${name} 2> /dev/null) && \

View File

@ -95,7 +95,7 @@ class BoxInfo:
ifname = f'eth{int(ifname[3]) - 1}' ifname = f'eth{int(ifname[3]) - 1}'
with open(ifdev) as f: with open(ifdev) as f:
self.network_interfaces[ifname] = addr = f.read().strip().lower() self.network_interfaces[ifname] = addr = f.read().strip().lower()
if ifname in ('eth0', 'enp1s0'): if ifname in ('eth0', 'enp1s0', 'end0'):
macaddr = addr macaddr = addr
self.main_if = ifname self.main_if = ifname
self.macaddr = macaddr self.macaddr = macaddr