forked from coolsnowwolf/lede
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
autocore: fix sfp unplugged speed display
- Loading branch information
1 parent
f6d0acb
commit 27a331a
Showing
2 changed files
with
41 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
#!/bin/sh | ||
|
||
a=$(ls /sys/class/net/*/device/uevent | grep -v wlan | awk -F '/' '{print $5}') | ||
b=$(echo "$a" | wc -l) | ||
rm -f /tmp/state/ethinfo | ||
|
||
echo -n "[" > /tmp/state/ethinfo | ||
|
||
for i in $(seq 1 $b) | ||
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 [ $e = yes ]; then | ||
l=1 | ||
else | ||
l=0 | ||
fi | ||
|
||
f=$(echo "$d" | grep "Speed" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g' | tr -d "Unknown!") | ||
[ -z "$f" ] && f=" - " | ||
|
||
g=$(echo "$d" | grep "Duplex" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g') | ||
if [ "$g" == "Full" ]; then | ||
x=1 | ||
else | ||
x=0 | ||
fi | ||
|
||
echo -n "$h \"$c\", \"status\": $l, \"speed\": \"$f\", \"duplex\": $x}," >> /tmp/state/ethinfo | ||
done | ||
|
||
sed -i 's/.$//' /tmp/state/ethinfo | ||
|
||
echo -n "]" >> /tmp/state/ethinfo | ||
|
||
cat /tmp/state/ethinfo | ||
#!/usr/bin/lua | ||
-- Copyright (C) 2022-2023 Tianling Shen <cnsztl@immortalwrt.org> | ||
-- Copyright (C) 2022-2023 Lean | ||
|
||
local util = require "luci.util" | ||
local jsonc = require "luci.jsonc" | ||
|
||
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 | ||
|
||
status = stat.carrier and 1 or 0 | ||
|
||
if not stat.carrier or not stat.speed or stat.speed:sub(1, 1) == "-" or stat.speed:find("65535") then | ||
speed = " - " | ||
else | ||
speed = stat.speed:sub(1, -2) .. "Mb/s" | ||
end | ||
|
||
if speed == " - " then | ||
duplex = 0 | ||
elseif stat.speed:sub(-1) == "F" then | ||
duplex = 1 | ||
else | ||
duplex = 0 | ||
end | ||
|
||
eth_info[#eth_info+1] = { name = ifname, status = status, | ||
speed = speed, duplex = duplex } | ||
end | ||
end | ||
|
||
table.sort(eth_info, | ||
function(a, b) | ||
return a.name < b.name | ||
end) | ||
|
||
print(jsonc.stringify(eth_info)) |