evenet/tinc-generate-mac
2015-01-25 19:06:01 +00:00

25 lines
599 B
Bash
Executable File

#!/usr/bin/env bash
set -eu
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
TINCRC="$DIR/tincrc"
MAC_ADDRESS=""
source "$TINCRC" || true
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.
printf 'export MAC_ADDRESS=02:1F:%02X:%02X:%02X:%02X\n' \
$[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] \
| tee -a "$TINCRC"
fi