evenet/tinc-generate-mac

25 lines
599 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
set -eu
2015-01-25 18:54:42 +00:00
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
TINCRC="$DIR/tincrc"
2015-01-25 19:06:01 +00:00
MAC_ADDRESS=""
2015-01-25 18:54:42 +00:00
source "$TINCRC" || true
2015-01-25 19:06:01 +00:00
if [ -n "$MAC_ADDRESS" ]; then
echo "Skip generating MAC: MAC_ADDRESS with value '$MAC_ADDRESS' already defined in '$TINCRC'."
exit 1
else
# Locally Administered Address Ranges:
#x2-xx-xx-xx-xx-xx
#x6-xx-xx-xx-xx-xx
#xA-xx-xx-xx-xx-xx
#xE-xx-xx-xx-xx-xx
# Replacing x with any hex value.
2015-01-25 18:54:42 +00:00
printf 'export MAC_ADDRESS=02:1F:%02X:%02X:%02X:%02X\n' \
$[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] \
2015-01-25 18:54:42 +00:00
| tee -a "$TINCRC"
fi