#!/bin/bash
################################################################################

. /etc/grml/lsb-functions

if [ "$(id -ru)" -ne 0 ] ; then
  echo "Error: please run this script with uid 0 (root)." >&2
  exit 1
fi

einfon "Checking network status... "

STATUS="Offline"
EXIT_CODE=1

GW="$(route -n | awk '/^0\.0\.0\.0/{print $2}')"
GWDEV="$(route -n | awk '/^0\.0\.0\.0/{print $NF}')"

if ping -c 3 "${GW}" >/dev/null ; then
  STATUS="Online (${GWDEV})"
  EXIT_CODE=0
fi

printf "%s\n" "$STATUS"
eend $EXIT_CODE
exit $EXIT_CODE
