wlan2eth/bridge/proxyarp/parprouted-monitor.sh

40 lines
1.0 KiB
Bash
Executable File

#!/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
# ==============================================================================
while true; do
if ethtool $ETH_IFACE | grep -q "Link detected: yes"; then
systemctl --quiet is-active parprouted || systemctl --quiet start parprouted
else
systemctl --quiet is-active parprouted && systemctl --quiet stop parprouted
fi
sleep 1
done