You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
deployment-iso/templates/scripts/includes/check-for-network

31 lines
749 B

#!/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}')"
SIPWISE_DEB='deb.sipwise.com'
DNS_SERVER="$( awk '/^nameserver/ {print $2; exit}' /etc/resolv.conf || true )"
if ping -c 3 "${GW}" >/dev/null \
|| ping -c 3 "${SIPWISE_DEB}" >/dev/null \
|| ping -c 3 "${DNS_SERVER:-1.1.1.1}" >/dev/null ; then
STATUS="Online (${GWDEV})"
EXIT_CODE=0
fi
printf "%s\n" "$STATUS"
eend $EXIT_CODE
exit $EXIT_CODE