desktop-utils/scripts/network.sh
2024-03-13 19:01:27 +01:00

40 lines
No EOL
745 B
Bash
Executable file

#!/bin/bash
ethernet() {
name="Wired"
image="ethernet"
}
wifi() {
wifiInfo=$(nmcli -t -f active,ssid,signal device wifi list)
signalStrength=$(awk -F: '/yes:/ {print $3}' <<< $wifiInfo)
name=$(awk -F: '/yes:/ {print $2}' <<< $wifiInfo)
if [[ $signalStrength>=70 ]]; then
image="wifiHigh"
elif [[ $signalStrength>=60 ]]; then
image="wifiMedium"
elif [[ $signalStrength>=40 ]]; then
image="wifiLow"
else
image="wifiVeryLow"
fi
}
name="No Connection"
image="n.A."
networkInfo=$(nmcli -f NAME,TYPE connection show --active | awk '!/loopback/ && NR > 1')
if [[ $(awk '/wifi/' <<< $networkInfo) ]]; then
wifi
fi
if [[ $(awk '/ethernet/' <<< $networkInfo) ]]; then
ethernet
fi
echo '{"name":"'$name'","image":"'$image'"}'