#!/usr/bin/env bash
set -o nounset #-o errexit
export PATH=/usr/sbin:/usr/bin:$PATH
ifaces='<%= node['dcos-grid']['bootstrap']['ip-detect']['interface'] %>'  # or eth0,...
for iface in `echo $ifaces | tr ',' ' '`; do
  #echo $iface
  ip addr show $iface > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    # first detected interface
    echo $(ip addr show $iface | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)
    break
  fi
done
