mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 04:13:31 +00:00
autocore: fix sfp unplugged speed display
This commit is contained in:
parent
f6d0acb91b
commit
27a331a57b
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2010-2022 OpenWrt.org
|
# Copyright (C) 2010-2023 OpenWrt.org
|
||||||
#
|
#
|
||||||
# This is free software, licensed under the GNU General Public License v2.
|
# This is free software, licensed under the GNU General Public License v2.
|
||||||
# See /LICENSE for more information.
|
# See /LICENSE for more information.
|
||||||
|
@ -1,39 +1,40 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/lua
|
||||||
|
-- Copyright (C) 2022-2023 Tianling Shen <cnsztl@immortalwrt.org>
|
||||||
|
-- Copyright (C) 2022-2023 Lean
|
||||||
|
|
||||||
a=$(ls /sys/class/net/*/device/uevent | grep -v wlan | awk -F '/' '{print $5}')
|
local util = require "luci.util"
|
||||||
b=$(echo "$a" | wc -l)
|
local jsonc = require "luci.jsonc"
|
||||||
rm -f /tmp/state/ethinfo
|
|
||||||
|
|
||||||
echo -n "[" > /tmp/state/ethinfo
|
local eth_info = {}
|
||||||
|
local ifname, stat
|
||||||
|
for ifname, stat in pairs(util.ubus("network.device", "status")) do
|
||||||
|
if ifname:match("^(eth%d+)$") == ifname then
|
||||||
|
local status, speed, duplex
|
||||||
|
|
||||||
for i in $(seq 1 $b)
|
status = stat.carrier and 1 or 0
|
||||||
do
|
|
||||||
h=$(echo '{"name":' )
|
|
||||||
c=$(echo "$a" | sed -n ${i}p)
|
|
||||||
d=$(ethtool $c)
|
|
||||||
|
|
||||||
e=$(echo "$d" | grep "Link detected" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g')
|
if not stat.carrier or not stat.speed or stat.speed:sub(1, 1) == "-" or stat.speed:find("65535") then
|
||||||
if [ $e = yes ]; then
|
speed = " - "
|
||||||
l=1
|
else
|
||||||
else
|
speed = stat.speed:sub(1, -2) .. "Mb/s"
|
||||||
l=0
|
end
|
||||||
fi
|
|
||||||
|
|
||||||
f=$(echo "$d" | grep "Speed" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g' | tr -d "Unknown!")
|
if speed == " - " then
|
||||||
[ -z "$f" ] && f=" - "
|
duplex = 0
|
||||||
|
elseif stat.speed:sub(-1) == "F" then
|
||||||
|
duplex = 1
|
||||||
|
else
|
||||||
|
duplex = 0
|
||||||
|
end
|
||||||
|
|
||||||
g=$(echo "$d" | grep "Duplex" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g')
|
eth_info[#eth_info+1] = { name = ifname, status = status,
|
||||||
if [ "$g" == "Full" ]; then
|
speed = speed, duplex = duplex }
|
||||||
x=1
|
end
|
||||||
else
|
end
|
||||||
x=0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -n "$h \"$c\", \"status\": $l, \"speed\": \"$f\", \"duplex\": $x}," >> /tmp/state/ethinfo
|
table.sort(eth_info,
|
||||||
done
|
function(a, b)
|
||||||
|
return a.name < b.name
|
||||||
|
end)
|
||||||
|
|
||||||
sed -i 's/.$//' /tmp/state/ethinfo
|
print(jsonc.stringify(eth_info))
|
||||||
|
|
||||||
echo -n "]" >> /tmp/state/ethinfo
|
|
||||||
|
|
||||||
cat /tmp/state/ethinfo
|
|
||||||
|
Loading…
Reference in New Issue
Block a user