sh: Add internet-check base script
Added script to sh base package to allow checking for internet connectivity. Checks both through system virtual filesystem and, as a fallback, through pinging google dns. Added a simple readme to sh module.
This commit is contained in:
parent
658e07e1b8
commit
3bf5becbe2
3 changed files with 48 additions and 4 deletions
24
sh/.local/bin/check-internet
Executable file
24
sh/.local/bin/check-internet
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#!/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
|
||||
Loading…
Add table
Add a link
Reference in a new issue