mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-02-12 18:41:51 +00:00
Rename device to previous name
This commit is contained in:
parent
1eb54b14c5
commit
f6589d981e
1 changed files with 34 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
# Copyright (C) 2020 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter
|
||||
|
||||
[ "$ACTION" = "add" ] || exit
|
||||
[ "$ACTION" = "add" ] || [ "$ACTION" = "bind" ] || exit
|
||||
[ -n "${INTERFACE}" ] || exit
|
||||
[ -n "${DEVPATH}" ] || exit
|
||||
|
||||
|
@ -12,14 +12,46 @@ _set_intf_name() {
|
|||
local device
|
||||
local ifname
|
||||
config_get device $intfname device
|
||||
config_get modalias $intfname modalias
|
||||
config_get ifname $intfname ifname
|
||||
[ -n "$device" ] && [ -n "$ifname" ] && [ "/sys${DEVPATH}" = "$device" ] && [ "$INTERFACE" != "$ifname" ] && {
|
||||
[ -n "$modalias" ] && {
|
||||
if [ -f /sys/class/net/${INTERFACE}/device/uevent ]; then
|
||||
#chk_modalias="$(cat /sys/class/net/${INTERFACE}/device/uevent | grep MODALIAS | cut -d '=' -f2 | tr -d '\n')"
|
||||
chk_modalias=$MODALIAS
|
||||
logger -t "OMR-Rename" "dir: $i - modalias: $modalias - chk_modalias: $chk_modalias - ifname: $ifname - INTERFACE: $INTERFACE"
|
||||
if [ "$modalias" = "$chk_modalias" ] && [ "$INTERFACE" != "$ifname" ]; then
|
||||
logger -t "OMR-Rename" "Rename ${INTERFACE} to ${ifname}"
|
||||
existif=0
|
||||
ip link set ${INTERFACE} down
|
||||
[ "$(ip link show ${ifname} 2>/dev/null)" != "" ] && {
|
||||
ip link set ${ifname} name ${ifname}tmp
|
||||
existif=1
|
||||
}
|
||||
ip link set ${INTERFACE} name ${ifname}
|
||||
ip link set ${ifname} up
|
||||
[ "$existif" = "1" ] && ip link set ${ifname}tmp ${$INTERFACE}
|
||||
fi
|
||||
elif [ -f /dev/${DEVICE_NAME} ] && [ "$modalias" = "$MODALIAS" ]; then
|
||||
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" ] && {
|
||||
logger -t "OMR-Rename" "Rename ${INTERFACE} to ${ifname}"
|
||||
ip link set ${INTERFACE} down
|
||||
existif=0
|
||||
[ "$(ip link show ${ifname} 2>/dev/null)" != "" ] && {
|
||||
ip link set ${ifname} name ${ifname}tmp
|
||||
existif=1
|
||||
}
|
||||
ip link set ${INTERFACE} name ${ifname}
|
||||
ip link set ${ifname} up
|
||||
[ "$existif" = "1" ] && ip link set ${ifname}tmp ${$INTERFACE}
|
||||
}
|
||||
}
|
||||
|
||||
config_load network
|
||||
config_foreach _set_intf_name interface
|
||||
config_foreach _set_intf_name interface
|
||||
|
|
Loading…
Reference in a new issue