anitazha / rpms / systemd

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