diff --git a/package/lean/autocore/files/arm/sbin/ethinfo b/package/lean/autocore/files/arm/sbin/ethinfo index 336676349..82d151de1 100755 --- a/package/lean/autocore/files/arm/sbin/ethinfo +++ b/package/lean/autocore/files/arm/sbin/ethinfo @@ -1,37 +1,39 @@ -#!/usr/bin/lua --- Copyright (C) 2022 Tianling Shen +#!/bin/sh -local util = require "luci.util" -local jsonc = require "luci.jsonc" +a=$(ls /sys/class/net/*/device/uevent | grep -v wlan | awk -F '/' '{print $5}') +b=$(echo "$a" | wc -l) +rm -f /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 +echo -n "[" > /tmp/state/ethinfo - 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 - speed = " - " - else - speed = stat.speed:sub(1, -2) .. "Mb/s" - end + e=$(echo "$d" | grep "Link detected" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g') + if [ $e = yes ]; then + l=1 + else + l=0 + fi - if stat.carrier and stat.speed:sub(-1) == "F" then - duplex = 1 - else - duplex = 0 - end + f=$(echo "$d" | grep "Speed" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g' | tr -d "Unknown!") + [ -z "$f" ] && f=" - " - eth_info[#eth_info+1] = { name = ifname, status = status, - speed = speed, duplex = duplex } - end -end + g=$(echo "$d" | grep "Duplex" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g') + if [ "$g" == "Full" ]; then + x=1 + else + x=0 + fi -table.sort(eth_info, - function(a, b) - return a.name < b.name - end) + echo -n "$h \"$c\", \"status\": $l, \"speed\": \"$f\", \"duplex\": $x}," >> /tmp/state/ethinfo +done -print(jsonc.stringify(eth_info)) +sed -i 's/.$//' /tmp/state/ethinfo + +echo -n "]" >> /tmp/state/ethinfo + +cat /tmp/state/ethinfo