valeriyvdovin / rpms / systemd

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