53 lines
1.5 KiB
Bash
Executable File
53 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# ==============================================================================
|
|
# Config
|
|
|
|
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/nat-config.sh" ]]; then
|
|
. "$DIR/../../config/nat-config.sh"
|
|
else
|
|
echo "$DIR/../../config/nat-config.sh missing!"
|
|
exit 1
|
|
fi
|
|
|
|
# Must be run as root
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
echo 'This script must be run as root.' >&2
|
|
exit 1
|
|
fi
|
|
|
|
# ==============================================================================
|
|
|
|
PREV_STATUS=""
|
|
|
|
while true; do
|
|
STATUS=$(cat /sys/class/net/$ETH_IFACE/carrier 2>/dev/null)
|
|
|
|
if [ "$STATUS" != "$PREV_STATUS" ]; then
|
|
if [ "$STATUS" == "0" ]; then
|
|
echo -e "\n----> Interface $ETH_IFACE has been unplugged."
|
|
bash "$DIR/bridge/bridge-reset.sh"
|
|
echo -e "--> Reset complete\n"
|
|
elif [ "$STATUS" == "1" ]; then
|
|
echo -e "\n----> Interface $ETH_IFACE has been plugged in."
|
|
# Clone the MAC first so that when we give the client an IP they'll know we're ready to go.
|
|
bash "$DIR/bridge/clone-client-mac.sh"
|
|
echo ""
|
|
bash "$DIR/bridge/bridge-lan.sh"
|
|
echo -e "--> Bridge complete\n"
|
|
else
|
|
echo -e "\n----> Interface $ETH_IFACE not found, doing nothing...\n"
|
|
fi
|
|
PREV_STATUS="$STATUS"
|
|
fi
|
|
sleep 1
|
|
done
|