Merge pull request #3 from basvandewiel/1-reliable-check-for-ip-connectivity

Abstract the IP-check to its own function
This commit is contained in:
Bas v.d. Wiel 2023-03-08 14:47:47 +01:00 committed by GitHub
commit 210608a8b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -50,13 +50,25 @@ MOUNT_AT_BOOT="yes"
#=========CODE STARTS HERE=========
# Check if we have an IPv4 address on any of the interfaces that is
# not a local loopback (127.0.0.0/8) or link-local (169.254.0.0/16) adddress.
function has_ip_address() {
ip addr show | grep 'inet ' | grep -vE '127.|169.254.' >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "true"
else
echo "false"
fi
}
# Run this script only once after getting an IP address
[ -f /tmp/nfs_mount.lock ] && exit 1
touch /tmp/nfs_mount.lock
if [ "${WAIT_FOR_SERVER}" == "yes" ]; then
echo -n "Waiting for getting an IP address."
until [ "$(ping -4 -c1 www.google.com &>/dev/null ; echo $?)" = "0" ]; do
while [ "$(has_ip_address)" != "true" ]; do
sleep 1
echo -n "."
done