daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
#!/bin/bash
923a60
923a60
SYSPATH="/sys/class/net/$1"
923a60
DEV_ID=$(<"${SYSPATH}/dev_id")
923a60
DEV_PORT=$(<"${SYSPATH}/dev_port")
923a60
PHYS_PORT_NAME=$(<"${SYSPATH}/phys_port_name")
923a60
923a60
#if PHYS_PORT_NAME is empty we are safe
923a60
[ -z "${PHYS_PORT_NAME}" ] && exit 0
923a60
923a60
# On-board index based names
923a60
if [ -n "${ID_NET_NAME_ONBOARD}" ]; then
923a60
    ID_NET_NAME_ONBOARD="${ID_NET_NAME_ONBOARD%d${DEV_PORT}}n${PHYS_PORT_NAME}"
923a60
fi
923a60
923a60
if [ -n "${DEV_ID}" ]; then
923a60
    DEV_ID=$(printf "%u" "${DEV_ID}")
923a60
    if [ "${DEV_ID}" -eq "0" ] && [ -n "${DEV_PORT}" ]; then
923a60
        # dev_port is decimal string, but we have a bug in net_id and we convert it to integer using base 16
923a60
        DEV_ID=$(printf "%u" "0x${DEV_PORT}")
923a60
    fi
923a60
fi
923a60
923a60
# PCI hot plug slot number based names
923a60
if [ -n "${ID_NET_NAME_SLOT}" ]; then
923a60
    ID_NET_NAME_SLOT="${ID_NET_NAME_SLOT%d${DEV_ID}}n${PHYS_PORT_NAME}"
923a60
fi
923a60
923a60
# PCI path based names
923a60
if [ -n "${ID_NET_NAME_PATH}" ]; then
923a60
    ID_NET_NAME_PATH="${ID_NET_NAME_PATH%d${DEV_ID}}n${PHYS_PORT_NAME}"
923a60
fi
923a60
923a60
[ -n "${ID_NET_NAME_ONBOARD}" ] && echo "ID_NET_NAME_ONBOARD=${ID_NET_NAME_ONBOARD}"
923a60
[ -n "${ID_NET_NAME_SLOT}" ] && echo "ID_NET_NAME_SLOT=${ID_NET_NAME_SLOT}"
923a60
[ -n "${ID_NET_NAME_PATH}" ] && echo "ID_NET_NAME_PATH=${ID_NET_NAME_PATH}"
923a60