home/.config/polybar/amidown.sh

61 lines
858 B
Bash
Raw Normal View History

2018-08-20 12:54:58 -05:00
#! /bin/bash
#
# netstatus.sh
# Copyright (C) 2018 rehashedsalt <salt@lap-th-e560-0>
#
# Distributed under terms of the MIT license.
#
# Global vars
if_default=""
ipv4_private=""
# Define our tests
function test-gateway {
if ip r | grep default > /dev/null 2>&1; then
ipr="$(ip r | grep default)"
ipv4_private="$(echo $ipr | awk '{print $3}')"
if_default="$(echo $ipr | awk '{print $5}')"
unset ipr
return 0
else
return 1
fi
}
function test-internet {
if ping -c 1 8.8.8.8 > /dev/null 2>&1; then
return 0
else
return 1
fi
}
function test-dns {
if ping -c 1 google.com > /dev/null 2>&1; then
return 0
else
return 1
fi
}
# Actually go through with them
if ! test-gateway; then
printf "NONE"
exit 1
fi
if ! test-internet; then
printf "LOCAL"
exit 2
fi
if ! test-dns; then
printf "NO DNS"
exit 3
fi
printf "UP"
exit 0