1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-15 03:51:51 +00:00
openmptcprouter-feeds/luci-app-openmptcprouter/root/etc/hotplug.d/net/99-omr-rename

71 lines
2.7 KiB
Text
Raw Normal View History

2020-07-03 17:12:42 +00:00
#!/bin/sh
# Copyright (C) 2020 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter
2020-09-04 19:56:50 +00:00
[ "$ACTION" = "add" ] || [ "$ACTION" = "bind" ] || exit
2020-07-03 17:12:42 +00:00
[ -n "${INTERFACE}" ] || exit
[ -n "${DEVPATH}" ] || exit
. /lib/functions.sh
_set_intf_name() {
local intfname=$1
local device
local ifname
config_get device $intfname device
2020-09-04 19:56:50 +00:00
config_get modalias $intfname modalias
2020-07-03 17:12:42 +00:00
config_get ifname $intfname ifname
config_get type $intfname ifname
if [ "$type" = "tunnel" ] || [ "$type" = "bridge" ]; then
return
fi
2020-09-04 19:56:50 +00:00
[ -n "$modalias" ] && {
if [ -f /sys/class/net/${INTERFACE}/device/uevent ]; then
2021-01-29 13:31:44 +00:00
mac=""
if [ -f /sys/class/net/${INTERFACE}/address ]; then
mac="$(cat /sys/class/net/${INTERFACE}/address | tr -d '\n')"
fi
2020-09-04 19:56:50 +00:00
chk_modalias=$MODALIAS
2020-11-03 20:33:09 +00:00
[ -z "$chk_modalias" ] && chk_modalias="$(cat /sys/class/net/${INTERFACE}/device/uevent | grep MODALIAS | cut -d '=' -f2 | tr -d '\n')"
if [ -n "$chk_modalias" ]; then
2021-01-29 13:31:44 +00:00
chk_modalias="${chk_modalias}-${mac}"
2021-01-07 19:00:01 +00:00
logger -t "OMR-Rename" "modalias: $modalias - chk_modalias: $chk_modalias - ifname: $ifname - INTERFACE: $INTERFACE"
2020-11-03 20:33:09 +00:00
if [ "$modalias" = "$chk_modalias" ] && [ "$INTERFACE" != "$ifname" ]; then
logger -t "OMR-Rename" "Rename ${INTERFACE} to ${ifname}"
2021-01-29 13:31:44 +00:00
existif="0"
2021-01-05 06:58:03 +00:00
ip link set ${INTERFACE} down 2>&1 >/dev/null
2020-11-03 20:33:09 +00:00
[ "$(ip link show ${ifname} 2>/dev/null)" != "" ] && {
2021-01-05 06:58:03 +00:00
ip link set ${ifname} name ${ifname}tmp 2>&1 >/dev/null
2021-01-29 13:31:44 +00:00
existif="1"
2020-11-03 20:33:09 +00:00
}
2021-01-05 06:58:03 +00:00
ip link set ${INTERFACE} name ${ifname} 2>&1 >/dev/null
ip link set ${ifname} up 2>&1 >/dev/null
2021-01-07 16:33:17 +00:00
[ "$existif" = "1" ] && ip link set ${ifname}tmp ${INTERFACE} 2>&1 >/dev/null
2020-11-03 20:33:09 +00:00
fi
2020-11-13 14:44:33 +00:00
fi
2020-11-03 20:33:09 +00:00
elif [ -f /dev/${DEVICE_NAME} ] && [ -n "$MODALIAS" ] && [ "$modalias" = "$MODALIAS" ]; then
2020-09-04 19:56:50 +00:00
if [ "$device" != "/dev/${DEVICE_NAME}" ]; then
ln -s /dev/${DEVICE_NAME} /dev/$intfname
uci -q set network.${intfname}.device="/dev/${intfname}"
fi
fi
}
[ -z "$modalias" ] && [ -n "$device" ] && [ -n "$ifname" ] && [ "/sys${DEVPATH}" = "$device" ] && [ "$INTERFACE" != "$ifname" ] && {
2021-01-07 19:00:01 +00:00
logger -t "OMR-Rename" "device: $device - devpath: $DEVPATH - ifname: $ifname - INTERFACE: $INTERFACE"
2020-07-03 17:12:42 +00:00
logger -t "OMR-Rename" "Rename ${INTERFACE} to ${ifname}"
2021-01-05 06:58:03 +00:00
ip link set ${INTERFACE} down 2>&1 >/dev/null
2021-01-29 13:31:44 +00:00
existif="0"
2020-09-04 19:56:50 +00:00
[ "$(ip link show ${ifname} 2>/dev/null)" != "" ] && {
2021-01-05 06:58:03 +00:00
ip link set ${ifname} name ${ifname}tmp 2>&1 >/dev/null
2021-01-29 13:31:44 +00:00
existif="1"
2020-09-04 19:56:50 +00:00
}
2021-01-05 06:58:03 +00:00
ip link set ${INTERFACE} name ${ifname} 2>&1 >/dev/null
ip link set ${ifname} up 2>&1 >/dev/null
2021-01-07 16:33:17 +00:00
[ "$existif" = "1" ] && ip link set ${ifname}tmp ${INTERFACE} 2>&1 >/dev/null
2020-07-03 17:12:42 +00:00
}
}
2021-01-07 19:00:01 +00:00
if [ "$(uci -q get openmptcprouter.settings.disableintfrename)" != "1" ]; then
config_load network
config_foreach _set_intf_name interface
2021-01-29 13:31:44 +00:00
# config_foreach _set_intf_name interface
fi