mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-06-10 14:22:05 +08:00
Revert "autocore: ethinfo: rewritten in lua"
This reverts commit 4f056f8ef3f929dad0be53ec0ba24037197e437a. Fixes: #10180, #10251
This commit is contained in:
parent
51dccebbdc
commit
613e76c9e0
@ -1,37 +1,39 @@
|
|||||||
#!/usr/bin/lua
|
#!/bin/sh
|
||||||
-- Copyright (C) 2022 Tianling Shen <cnsztl@immortalwrt.org>
|
|
||||||
|
|
||||||
local util = require "luci.util"
|
a=$(ls /sys/class/net/*/device/uevent | grep -v wlan | awk -F '/' '{print $5}')
|
||||||
local jsonc = require "luci.jsonc"
|
b=$(echo "$a" | wc -l)
|
||||||
|
rm -f /tmp/state/ethinfo
|
||||||
|
|
||||||
local eth_info = {}
|
echo -n "[" > /tmp/state/ethinfo
|
||||||
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
|
for i in $(seq 1 $b)
|
||||||
|
do
|
||||||
|
h=$(echo '{"name":' )
|
||||||
|
c=$(echo "$a" | sed -n ${i}p)
|
||||||
|
d=$(ethtool $c)
|
||||||
|
|
||||||
if stat.speed:sub(1, 1) == "-" then
|
e=$(echo "$d" | grep "Link detected" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g')
|
||||||
speed = " - "
|
if [ $e = yes ]; then
|
||||||
else
|
l=1
|
||||||
speed = stat.speed:sub(1, -2) .. "Mb/s"
|
else
|
||||||
end
|
l=0
|
||||||
|
fi
|
||||||
|
|
||||||
if stat.carrier and stat.speed:sub(-1) == "F" then
|
f=$(echo "$d" | grep "Speed" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g' | tr -d "Unknown!")
|
||||||
duplex = 1
|
[ -z "$f" ] && f=" - "
|
||||||
else
|
|
||||||
duplex = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
eth_info[#eth_info+1] = { name = ifname, status = status,
|
g=$(echo "$d" | grep "Duplex" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g')
|
||||||
speed = speed, duplex = duplex }
|
if [ "$g" == "Full" ]; then
|
||||||
end
|
x=1
|
||||||
end
|
else
|
||||||
|
x=0
|
||||||
|
fi
|
||||||
|
|
||||||
table.sort(eth_info,
|
echo -n "$h \"$c\", \"status\": $l, \"speed\": \"$f\", \"duplex\": $x}," >> /tmp/state/ethinfo
|
||||||
function(a, b)
|
done
|
||||||
return a.name < b.name
|
|
||||||
end)
|
|
||||||
|
|
||||||
print(jsonc.stringify(eth_info))
|
sed -i 's/.$//' /tmp/state/ethinfo
|
||||||
|
|
||||||
|
echo -n "]" >> /tmp/state/ethinfo
|
||||||
|
|
||||||
|
cat /tmp/state/ethinfo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user