mirror of
				https://github.com/Ysurac/openmptcprouter-feeds.git
				synced 2025-03-09 15:40:03 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			63 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
#!/bin/sh
 | 
						|
# Copyright (C) 2020 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter
 | 
						|
 | 
						|
[ "$ACTION" = "add" ] || [ "$ACTION" = "bind" ] || exit
 | 
						|
[ -n "${INTERFACE}" ] || exit
 | 
						|
[ -n "${DEVPATH}" ] || exit
 | 
						|
 | 
						|
. /lib/functions.sh
 | 
						|
 | 
						|
_set_intf_name() {
 | 
						|
	local intfname=$1
 | 
						|
	local device
 | 
						|
	local ifname
 | 
						|
	config_get device $intfname device
 | 
						|
	config_get modalias $intfname modalias
 | 
						|
	config_get ifname $intfname ifname
 | 
						|
	config_get type $intfname ifname
 | 
						|
	if [ "$type" = "tunnel" ] || [ "$type" = "bridge" ]; then
 | 
						|
		return
 | 
						|
	fi
 | 
						|
	[ -n "$modalias" ] && {
 | 
						|
		if [ -f /sys/class/net/${INTERFACE}/device/uevent ]; then
 | 
						|
			chk_modalias=$MODALIAS
 | 
						|
			[ -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
 | 
						|
				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
 | 
						|
			fi
 | 
						|
		elif [ -f /dev/${DEVICE_NAME} ] && [ -n "$MODALIAS" ] && [ "$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
 |