evenet/tinc-generate-mac

29 lines
653 B
Plaintext
Raw Permalink 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
2015-03-12 22:36:20 +00:00
if [ -f "$TINCRC" ]; then
source "$TINCRC"
else
export MAC_ADDRESS=""
fi
2015-01-25 18:54:42 +00:00
2015-03-12 22:36:20 +00:00
if [[ -n "$MAC_ADDRESS" ]]; then
2015-01-25 19:06:01 +00:00
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