#!/bin/bash
# Called by udev with the interface name; derives the MAC from the SoC serial (fuses),
# falling back to /etc/machine-id.
set -u
ifname="${1:?interface name}"
id="$(cat /sys/devices/soc0/serial_number 2> /dev/null)"
[[ -n ${id} ]] || id="$(< /etc/machine-id)"
h="$(printf 'wlan:%s' "${id}" | sha256sum | cut -c1-10)"
exec /usr/sbin/ip link set dev "${ifname}" address "02:${h:0:2}:${h:2:2}:${h:4:2}:${h:6:2}:${h:8:2}"
