Files
boxtools/sethostname.sh
Markus Zolliker 206d58ea91 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
2025-08-21 15:48:42 +02:00

23 lines
715 B
Bash

if [[ -f /sys/class/net/end0/address ]]; then
ETHNAME=$(cat /sys/class/net/end0/address)
BASED=end0
elif [[ -f /sys/class/net/eth0/address ]]; then
ETHNAME=$(cat /sys/class/net/eth0/address)
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
BOXID=${ETHNAME//:/}
BOXID=${BOXID: -6}
HOSTNAME=box$BOXID
else
FOUND=$(basename ${FOUND[0]}) # remove directory part
HOSTNAME=${FOUND%%.cfg} # remove extension
fi
echo "set hostname to $HOSTNAME based on $BASED $ETHNAME"
echo $HOSTNAME > /etc/hostname
echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts