2022-10-08 12:47:57 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# network module for status/stellar
|
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# load config
|
2022-11-27 01:12:14 +01:00
|
|
|
module_config
|
|
|
|
[ -e "$HOME/.config/speedwm/statusrc" ] && . $HOME/.config/speedwm/statusrc
|
|
|
|
[ "$ENABLE_ITEM6" = "true" ] || exit
|
2022-10-21 13:35:02 +02:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
# get stats
|
|
|
|
GETNSTAT() {
|
|
|
|
R1="$(cat /sys/class/net/[ew]*/statistics/rx_bytes || exit)"
|
|
|
|
T1="$(cat /sys/class/net/[ew]*/statistics/tx_bytes || exit)"
|
|
|
|
sleep 0.1
|
|
|
|
R2="$(cat /sys/class/net/[ew]*/statistics/rx_bytes || exit)"
|
|
|
|
T2="$(cat /sys/class/net/[ew]*/statistics/tx_bytes || exit)"
|
|
|
|
TXPMS="$(expr $T2 - $T1)"
|
|
|
|
RXPMS="$(expr $R2 - $R1)"
|
|
|
|
TX="$(expr $TXPMS / 1024 "*" 10)"
|
|
|
|
RX="$(expr $RXPMS / 1024 "*" 10)"
|
2022-11-27 02:29:52 +01:00
|
|
|
[ ! -z "$TX" ] && printf "$TX\n" > /tmp/module_net_tx
|
|
|
|
[ ! -z "$RX" ] && printf "$RX\n" > /tmp/module_net_rx
|
2022-11-27 01:12:14 +01:00
|
|
|
}
|
2022-10-21 13:35:02 +02:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
[ ! -e "/tmp/module_net_tx" ] && GETNSTAT
|
|
|
|
|
|
|
|
NETWORK_TRANSMITTED="$(cat /tmp/module_net_tx)"
|
|
|
|
NETWORK_RECEIVED="$(cat /tmp/module_net_rx)"
|
2022-10-21 13:35:02 +02:00
|
|
|
|
|
|
|
# click
|
|
|
|
CLICK() {
|
|
|
|
# values
|
|
|
|
ICON="$ITEM6_ICON"
|
2022-11-27 01:12:14 +01:00
|
|
|
[ -e "/tmp/speedwm-button" ] && BUTTON="$(cat /tmp/speedwm-button)" || BUTTON="0"
|
|
|
|
[ -z "$TERMINAL" ] && TERMINAL=st
|
|
|
|
[ ! -z "$ICON" ] && ICONSPACING=" " # one character spacing
|
2022-10-21 13:35:02 +02:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
# check value of button
|
2022-10-21 13:35:02 +02:00
|
|
|
case "$BUTTON" in
|
2022-11-27 01:12:14 +01:00
|
|
|
"3") $TERMINAL -e bmon ; return ;;
|
2022-10-21 13:35:02 +02:00
|
|
|
esac
|
|
|
|
|
|
|
|
# send the notification
|
|
|
|
SEND_NOTIF() {
|
2022-11-01 20:38:29 +01:00
|
|
|
FULL_NETWORK="${ICON}${ICONSPACING}${NETWORK_TRANSMITTED} transmitted, ${NETWORK_RECEIVED} received."
|
2022-10-21 13:35:02 +02:00
|
|
|
notify-send "$FULL_NETWORK"
|
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
# some information
|
2022-10-21 13:35:02 +02:00
|
|
|
echo "Notification sent successfully!"
|
|
|
|
echo "INFO: $FULL_NETWORK"
|
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
return
|
2022-10-21 13:35:02 +02:00
|
|
|
}
|
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
command -v notify-send > /dev/null && SEND_NOTIF || echo "FATAL: libnotify not installed, can't send notification."
|
|
|
|
return
|
2022-10-08 12:47:57 +02:00
|
|
|
}
|
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# information itself
|
|
|
|
PRINT() {
|
2022-11-27 02:29:52 +01:00
|
|
|
[ ! -z "$NETWORK_TRANSMITTED" ] && [ ! -z "$NETWORK_RECEIVED" ] && echo "$ITEM6_SEPARATOR $ITEM6_ICON $ITEM6_FORMAT" | sed "s|@t|$NETWORK_TRANSMITTED|g; s|@r|$NETWORK_RECEIVED|g"
|
2022-10-21 13:35:02 +02:00
|
|
|
}
|
2022-10-08 12:47:57 +02:00
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# argument 1
|
2022-11-27 01:12:14 +01:00
|
|
|
case "$1" in
|
2022-10-21 13:35:02 +02:00
|
|
|
"") CLICK ;;
|
2022-11-26 19:16:22 +01:00
|
|
|
"--print-file") PRINT > /tmp/module_net ;;
|
|
|
|
"--print") PRINT ;;
|
2022-10-21 13:35:02 +02:00
|
|
|
"--click") CLICK ;;
|
|
|
|
esac
|
2022-11-01 20:38:29 +01:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
# gather some stats before exiting
|
|
|
|
GETNSTAT
|