From 206d58ea91e2eb89d10f2184bbb71656e59906bc Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Thu, 21 Aug 2025 15:45:42 +0200 Subject: [PATCH] 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 --- sethostname.sh | 8 ++++---- to_system/etc/profile.d/welcome.sh | 6 ++++-- utils.py | 8 ++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/sethostname.sh b/sethostname.sh index b79f7e4..04c2147 100644 --- a/sethostname.sh +++ b/sethostname.sh @@ -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 diff --git a/to_system/etc/profile.d/welcome.sh b/to_system/etc/profile.d/welcome.sh index 021c1a2..62c90b1 100755 --- a/to_system/etc/profile.d/welcome.sh +++ b/to_system/etc/profile.d/welcome.sh @@ -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 () { diff --git a/utils.py b/utils.py index de306e0..85d28d3 100644 --- a/utils.py +++ b/utils.py @@ -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