sb-internet: rewrite with nmcli
This commit is contained in:
parent
0f7c7607e7
commit
28b7dab483
|
@ -1,73 +1,62 @@
|
|||
#!/bin/sh
|
||||
|
||||
# TODO: rewrite this with nmcli
|
||||
|
||||
shift=""
|
||||
|
||||
# Ethernet
|
||||
for if in /sys/class/net/*; do
|
||||
[ "$(cat "$if/type")" = 1 ] || continue
|
||||
|
||||
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=" "
|
||||
done
|
||||
|
||||
# WLAN
|
||||
for if in /sys/class/net/*; do
|
||||
eval "$(cat "$if/uevent")"
|
||||
|
||||
[ "$DEVTYPE" = "wlan" ] || continue
|
||||
unset DEVTYPE
|
||||
|
||||
ifname=$(basename "$if")
|
||||
|
||||
if grep -vxq '0x\(1\|9\)003' "$if/flags"; then
|
||||
wifi_icon=""
|
||||
wifi() {
|
||||
if grep -vxq '0x\(1\|9\)003' "$info/flags"; then
|
||||
icon=""
|
||||
else
|
||||
case "$(cat "$if/operstate")" in
|
||||
up)
|
||||
percent=$(awk -v interface="$INTERFACE" '$1==interface {gsub(/[^0-9]/,"",$3); print $3}' /proc/net/wireless)
|
||||
case "$state" in
|
||||
connected)
|
||||
percent=$(awk -v interface="$device:" '$1==interface {gsub(/[^0-9]/,"",$3); print $3}' /proc/net/wireless)
|
||||
# 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="" ;;
|
||||
$((percent >= 80))) icon="" ;;
|
||||
$((percent >= 60))) icon="" ;;
|
||||
$((percent >= 40))) icon="" ;;
|
||||
$((percent >= 20))) icon="" ;;
|
||||
$((percent >= 0))) icon="" ;;
|
||||
esac
|
||||
;;
|
||||
down) wifi_icon="" ;;
|
||||
*) wifi_icon="" ;;
|
||||
disconnected) icon="" ;;
|
||||
*) icon="" ;;
|
||||
esac
|
||||
printf "%b" "$shift$icon $connection"
|
||||
shift=" "
|
||||
fi
|
||||
}
|
||||
|
||||
printf "%b" "$shift$wifi_icon $ifname"
|
||||
wireguard() {
|
||||
printf "%b" "$shift $connection"
|
||||
shift=" "
|
||||
done
|
||||
}
|
||||
|
||||
# Wireguard
|
||||
for if in /sys/class/net/*; do
|
||||
eval "$(cat "$if/uevent")"
|
||||
ethernet() {
|
||||
case "$state" in
|
||||
connected) icon="" ;;
|
||||
unavailable) icon="" ;;
|
||||
disconnected) icon="" ;;
|
||||
*) icon="" ;;
|
||||
esac
|
||||
|
||||
[ "$DEVTYPE" = "wireguard" ] || continue
|
||||
unset DEVTYPE
|
||||
|
||||
ifname=$(basename "$if")
|
||||
|
||||
printf "%b" "$shift $ifname"
|
||||
printf "%b" "$shift$icon"
|
||||
shift=" "
|
||||
done
|
||||
}
|
||||
|
||||
printf "\n"
|
||||
fallback() {
|
||||
:
|
||||
}
|
||||
|
||||
for x in $(nmcli --terse device status); do
|
||||
device="$(echo "$x" | cut -d: -f1)"
|
||||
type="$(echo "$x" | cut -d: -f2)"
|
||||
state="$(echo "$x" | cut -d: -f3)"
|
||||
connection="$(echo "$x" | cut -d: -f4)"
|
||||
info="/sys/class/net/${device}"
|
||||
|
||||
case "$type" in
|
||||
wifi | wireguard | ethernet) $type ;;
|
||||
*) fallback ;;
|
||||
esac
|
||||
unset device type state connection info icon
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue