support the case of no enp0 if is present

if seems on ionopimax, with predictable network IF on, the
main (only) interface is named enx....... instead of end0
this is a fix to support it
This commit is contained in:
2025-08-21 15:45:42 +02:00
parent 327496553d
commit 206d58ea91
3 changed files with 16 additions and 6 deletions

View File

@@ -1,12 +1,12 @@
if [[ -f /sys/class/net/end0/address ]]; then
ETHNAME=$(cat /sys/class/net/end0/address)
BASED=end0
else
elif [[ -f /sys/class/net/eth0/address ]]; then
ETHNAME=$(cat /sys/class/net/eth0/address)
if [[ -z "$ETHNAME" ]]; then
ETHNAME=undefined
fi
BASED=eth0
else
ETHNAME=$(cat /sys/class/net/en*/address)
BASED=$(echo /sys/class/net/en*/address)
fi
FOUND=($(grep -l -r MAC=$ETHNAME /home/l_samenv/boxtools/cfg))
if [ -z "$FOUND" ]; then

View File

@@ -1,10 +1,12 @@
export EDITOR=nano
echo "-----------------------------------------------------"
echo "Welcome to $HOSTNAME $(hostname -I)"
if [[ -f /sys/class/net/eth0/address ]]; then
if [[ -f /sys/class/net/end0/address ]]; then
ETHNAME=$(cat /sys/class/net/end0/address)
elif [[ -f /sys/class/net/eth0/address ]]; then
ETHNAME=$(cat /sys/class/net/eth0/address)
else
ETHNAME=$(cat /sys/class/net/end0/address)
ETHNAME=$(cat /sys/class/net/en*/address)
fi
echo "ethernet addr $ETHNAME"
function service_status () {

View File

@@ -98,6 +98,14 @@ class BoxInfo:
if ifname in ('eth0', 'enp1s0', 'end0'):
macaddr = addr
self.main_if = ifname
if self.main_if is None:
if len(self.network_interfaces) == 1:
self.main_if = list(self.network_interfaces)[0]
macaddr = self.network_interfaces[self.main_if]
elif self.network_interfaces:
raise RuntimeError(f'ambiguous main if: {self.network_interfaces}')
else:
raise RuntimeError('no main if found')
self.macaddr = macaddr
if macaddr:
self.id = int(''.join(macaddr.split(':')[-3:]), 16) & 0xffffff