Created
July 22, 2017 16:34
-
-
Save deric/cb304384e76a6cdcbf69ae8f8e59cbb0 to your computer and use it in GitHub Desktop.
DC/OS ip-detect script for "deterministic network interfaces naming"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o nounset -o errexit | |
export PATH=/usr/sbin:/usr/bin:$PATH | |
function msg { out "$*" >&1 ;} | |
function out { printf '%s\n' "$*" ;} | |
function showint { | |
msg $(ip addr show $1 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1) | |
} | |
if [[ -d /sys/class/net/eth0 ]]; then | |
showint "eth0" | |
else | |
# udev names network devices by their MAC addresses | |
# chooses first enp device (so far best heuristic) | |
showint $(ls -d /sys/class/net/enp* | tail -n +1 | cut -d \/ -f 5) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment