sb-internet: refactor
This commit is contained in:
parent
f32efeaee1
commit
ff1e3d8ed5
|
@ -1,38 +1,72 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# TODO: rewrite this with nmcli
|
||||||
|
|
||||||
shift=""
|
shift=""
|
||||||
|
|
||||||
# Ethernet
|
# Ethernet
|
||||||
for if in /sys/class/net/*; do
|
for if in /sys/class/net/*; do
|
||||||
eval "$(cat "$if/uevent")"
|
[ "$(cat "$if/type")" = 1 ] || continue
|
||||||
[ -z "$DEVTYPE" ] || continue
|
|
||||||
printf "%b" "$shift"
|
ifname=$(basename "$if")
|
||||||
|
|
||||||
|
echo "$ifname" | grep -q \
|
||||||
|
-e "^br" \
|
||||||
|
-e "^docker" &&
|
||||||
|
continue
|
||||||
|
|
||||||
|
case "$(cat "$if/operstate")" in
|
||||||
|
up) eth_icon="" ;;
|
||||||
|
down) eth_icon="" ;;
|
||||||
|
*) eth_icon="" ;;
|
||||||
|
esac
|
||||||
|
printf "%b" "$shift$eth_icon $ifname"
|
||||||
shift=" "
|
shift=" "
|
||||||
done
|
done
|
||||||
|
|
||||||
# WLAN
|
# WLAN
|
||||||
for if in /sys/class/net/*; do
|
for if in /sys/class/net/*; do
|
||||||
eval "$(cat "$if/uevent")"
|
eval "$(cat "$if/uevent")"
|
||||||
|
|
||||||
[ "$DEVTYPE" = "wlan" ] || continue
|
[ "$DEVTYPE" = "wlan" ] || continue
|
||||||
|
unset DEVTYPE
|
||||||
|
|
||||||
|
ifname=$(basename "$if")
|
||||||
|
|
||||||
if grep -vxq '0x\(1\|9\)003' "$if/flags"; then
|
if grep -vxq '0x\(1\|9\)003' "$if/flags"; then
|
||||||
wifi_icon=""
|
wifi_icon=""
|
||||||
else
|
else
|
||||||
case "$(cat "$if/operstate")" in
|
case "$(cat "$if/operstate")" in
|
||||||
up) wifi_icon="" ;;
|
up)
|
||||||
down) wifi_icon="" ;;
|
percent=$(awk -v interface="$INTERFACE" '$1==interface {gsub(/[^0-9]/,"",$3); print $3}' /proc/net/wireless)
|
||||||
dormant) wifi_icon="" ;;
|
# shellcheck disable=SC2194
|
||||||
|
case 1 in
|
||||||
|
$((percent >= 0))) wifi_icon="" ;;
|
||||||
|
$((percent >= 20))) wifi_icon="" ;;
|
||||||
|
$((percent >= 40))) wifi_icon="" ;;
|
||||||
|
$((percent >= 60))) wifi_icon="" ;;
|
||||||
|
$((percent >= 80))) wifi_icon="" ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
down) wifi_icon="" ;;
|
||||||
|
*) wifi_icon="" ;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
percent="$(grep "$INTERFACE" /proc/net/wireless | tr -s ' ' | cut -d ' ' -f3 | tr -dc "[:digit:]")"
|
|
||||||
printf "%b" "$shift$wifi_icon $percent"
|
printf "%b" "$shift$wifi_icon $ifname"
|
||||||
shift=" "
|
shift=" "
|
||||||
done
|
done
|
||||||
|
|
||||||
# Wireguard
|
# Wireguard
|
||||||
for if in /sys/class/net/*; do
|
for if in /sys/class/net/*; do
|
||||||
eval "$(cat "$if/uevent")"
|
eval "$(cat "$if/uevent")"
|
||||||
|
|
||||||
[ "$DEVTYPE" = "wireguard" ] || continue
|
[ "$DEVTYPE" = "wireguard" ] || continue
|
||||||
printf "%b" "$shift"
|
unset DEVTYPE
|
||||||
|
|
||||||
|
ifname=$(basename "$if")
|
||||||
|
|
||||||
|
printf "%b" "$shift $ifname"
|
||||||
shift=" "
|
shift=" "
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue