THEAARBS tools - speedof

Published 08-04-2018 13:03:49

Raw

#!/bin/sh
Say() { echo -e "$1\n$2" ; notify-send "$1" "$2" ;}

get_interfaces() {
    for i in $all_interfaces ; do
        interface_name="${BLOCK_INSTANCE:-$i}"
        case $interface_name in
            eno*|enp*|eth*) LanInterface=$interface_name ;;
            wlp*|wlan*) WLanInterface=$interface_name ;;
        esac
    done ;}

speed_meter() {
    $(ifinstalled speedometer) &&
    all_interfaces=$(ls /sys/class/net)
    get_interfaces $all_interfaces
    case $1 in
        lan) the_interface=$LanInterface ;;
        wlan) the_interface=$WLanInterface ;;
    esac
    [[ -z $(ip addr show $the_interface | perl -n -e '/inet ([^\/]+)/ && print $1') ]] &&
    Say "⛔ Error: interface $the_interface is not connected" ||
    speedometer -t $the_interface ;}

get_speedlimits() {
    $(ifinstalled speedtest) &&
    Say "⌛ Testing internet speeds." "This might take a minute."
    speedlimits=( $(speedtest | grep -E 'Download:|Upload:') )
    speeddown=${speedlimits[@]:0:3} speedup=${speedlimits[@]:3:5}
    Say "⬇ $speeddown" "⬆ $speedup" ;}

case $1 in
    lan|-l) speed_meter lan ;;
    wlan|wifi|-w) speed_meter wlan ;;
    wan|me|net|-i) get_speedlimits ;;
    *) echo -e "Usage:\n  speedof [argument]\n\nAvailable arguments:\n  -l, lan - get wired ethernet speeds\n  -w, wlan, wifi - get wireless speeds\n  -i, wan, me, net - get internet speeds" ;;
esac