ipsec-interfaces: Resolve any remote hostnames
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 22 Jan 2019 11:34:49 +0000 (11:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 4 Feb 2019 18:20:36 +0000 (18:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/ipsec-interfaces

index c137a77..0e43fcc 100644 (file)
@@ -37,6 +37,12 @@ log() {
        logger -t ipsec "$@"
 }
 
+resolve_hostname() {
+       local hostname="${1}"
+
+       dig +short A "${hostname}" | tail -n1
+}
+
 main() {
        # Register local variables
        local "${VARS[@]}"
@@ -85,6 +91,11 @@ main() {
                                fi
                        fi
 
+                       # Resolve any hostnames
+                       if [[ ! ${remote} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
+                               remote="$(resolve_hostname "${remote}")"
+                       fi
+
                        local args=(
                                "local" "${local}"
                                "remote" "${remote}"