wlan2eth/bridge/nat/clone-client-mac.sh

53 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2023-06-13 14:14:38 -06:00
#!/bin/bash
# ==============================================================================
# Config and setup
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do
DIR=$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE
done
DIR=$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)
2023-06-20 10:29:28 -06:00
if [[ -f "$DIR/../../config/nat-config.sh" ]]; then
. "$DIR/../../config/nat-config.sh"
2023-06-13 14:14:38 -06:00
else
2023-06-20 10:29:28 -06:00
echo "$DIR/../../config/nat-config.sh missing!"
2023-06-13 14:14:38 -06:00
exit 1
fi
if [ "$(id -u)" -ne 0 ]; then
echo 'This script must be run as root.' >&2
exit 1
fi
. "$DIR/get_client_mac_address.sh"
# ==============================================================================
MAC_OTHR=$(get_client_mac_address $ETH_IFACE)
if [ -z "$MAC_OTHR" ]; then
echo "Bridged client not found! MAC address was empty."
exit 1
else
echo "Cloning MAC: $MAC_OTHR"
fi
# Clone MAC address of the wired-only device to the WiFi device
ifconfig $WLAN_IFACE down
ifconfig $WLAN_IFACE hw ether $MAC_OTHR
ifconfig $WLAN_IFACE up
echo "Set $WLAN_IFACE MAC to $MAC_OTHR"
while true; do
WLAN_IFACE_IP=$(ip -4 -br addr show $WLAN_IFACE | grep -Po "\\d+\\.\\d+\\.\\d+\\.\\d+")
if [ -n "${WLAN_IFACE_IP}" ]; then
echo "Got DHCP IP: $WLAN_IFACE_IP"
break
fi
echo "Waiting for $WLAN_IFACE to get an IP..."
sleep 5
done