#!/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/config.sh" ]]; then source "$DIR/config/config.sh" else echo "config/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." bash "$DIR/bridge/bridge-lan.sh" bash "$DIR/bridge/clone-client-mac.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