#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
set -eu

interface=${1:?}
address=$(cat "/sys/class/net/${interface}/address")
[[ "${address}" == "00:00:00:00:00:00" ]] || exit 0

hash=$(printf '%s-wifi' "$(cat /etc/machine-id)" | sha256sum)
printf -v address '02:%s:%s:%s:%s:%s' "${hash:0:2}" "${hash:2:2}" "${hash:4:2}" "${hash:6:2}" "${hash:8:2}"
exec ip link set dev "${interface}" address "${address}"
