25 lines
451 B
Text
25 lines
451 B
Text
|
#!/usr/bin/env sh
|
||
|
#
|
||
|
# Check for internet connectivity.
|
||
|
# Returns 0 if connectivity exists, 1 if it does not.
|
||
|
|
||
|
hasconnec=0
|
||
|
for intf in /sys/class/net/*; do
|
||
|
case $intf in
|
||
|
"/sys/class/net/lo") break ;;
|
||
|
*)
|
||
|
[ "$(cat "$intf/carrier")" = 1 ] && hasconnec=1
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
if [ $hasconnec -ne 1 ]; then
|
||
|
ping -q -w 1 -c 1 8.8.8.8 >/dev/null 2>&1 && hasconnec=1
|
||
|
fi
|
||
|
|
||
|
if [ $hasconnec -eq 1 ]; then
|
||
|
exit 0
|
||
|
else
|
||
|
exit 1
|
||
|
fi
|