#!/usr/bin/env bash 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) if [[ -f "$DIR/../../config/arp-config.sh" ]]; then . "$DIR/../../config/arp-config.sh" else echo "$DIR/../../config/arp-config.sh missing!" exit 1 fi if [ "$(id -u)" -ne 0 ]; then echo 'This script must be run as root.' >&2 exit 1 fi if [ ! -f "/sys/class/net/$ETH_IFACE/operstate" ]; then echo "ERROR: $ETH_IFACE does not exist?" echo "File does not exist: /sys/class/net/$ETH_IFACE/operstate" exit 1 fi EXITING=0 function ctrl_c() { # Reset the interfaces if [ $EXITING -eq 0 ]; then # prevent running this multiple times EXITING=1 echo "Cleaning up..." ip link set $WLAN_IFACE promisc off ip link set dev $ETH_IFACE down ip link set dev $ETH_IFACE up ip addr del $(/sbin/ip -4 -br addr show $WLAN_IFACE | /bin/grep -Po "\\d+\\.\\d+\\.\\d+\\.\\d+")/32 dev $ETH_IFACE exit fi } # ============================================================================== while ! ethtool $ETH_IFACE | grep -q "Link detected: yes"; do echo "Waiting for wired interface $ETH_IFACE to come up..." sleep 10s done # Clone our DCHP-allocated IP from wlan0 to eth0 so dhcp-helper will relay for the correct subnet echo "Initializing..." trap ctrl_c SIGINT trap ctrl_c SIGTERM ip addr add $(/sbin/ip -4 -br addr show $WLAN_IFACE | /bin/grep -Po "\\d+\\.\\d+\\.\\d+\\.\\d+")/32 dev $ETH_IFACE ip link set $WLAN_IFACE promisc on 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 break fi echo "Waiting for wireless interface $WLAN_IFACE to get an IP..." sleep 10s done parprouted -d $ETH_IFACE $WLAN_IFACE