Merge pull request #14 from basvandewiel/7-refactor-a-check-for-minimally-viable-configuration

Add function for config checking and use it.
This commit is contained in:
Bas v.d. Wiel 2023-03-09 16:30:10 +01:00 committed by GitHub
commit f3c9b59d41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 2 deletions

View File

@ -49,9 +49,9 @@ WAIT_FOR_SERVER="yes"
# it will create start/kill scripts in /etc/network/if-up.d and /etc/network/if-down.d.
MOUNT_AT_BOOT="yes"
#=========NO USER-SERVICEABLE PARTS BELOW THIS LINE=====
#=========CODE STARTS HERE=========
#=========FUNCTION LIBRARY==============================
# 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.
@ -65,6 +65,30 @@ function has_ip_address() {
fi
}
# Check if the script's configuration is minimally viable
function viable_config() {
local VIABLE="false"
if [ "${SERVER}" != "" ]; then
VIABLE="true"
fi
if [ "${SERVER_PATH}" != "" ]; then
VIABLE="true"
fi
if [ "${VIABLE}" == "true" ]; then
echo "true"
else
echo "false"
fi
}
#=========BUSINESS LOGIC================================
if [ "$(viable_config)" == "false" ]; then
echo "You need to set both SERVER and SERVER_PATH variables."
exit 1
fi
# Run this script only once after getting an IP address
[ -f /tmp/nfs_mount.lock ] && exit 1
touch /tmp/nfs_mount.lock