#!/bin/sh

# Only relevant on systemd systems (ClearOS 7)
[ -x /usr/bin/systemctl ] || exit 0

# Can someone explain how to get rid of failed systemd unit files?
# Why is this even hard to figure out?  Why?

# For the dozens of other event implementation, we only make changes when 
# changes are truly necessary.  There's very low trust with systemd, so 
# *always* make the changes for now.  The "network configuration" event is
# fairly rare, so we can live with it for now.  Sigh.

# Grab a list of all arpwatch units
UNITS=`systemctl list-units | grep "^[[:space:]]*arpwatch" | awk '{ print $1 }'`

for UNIT in $UNITS; do
    systemctl stop $UNIT
    systemctl disable $UNIT
done

IFACES=`network --get-lan-interfaces 2>/dev/null`

for IFACE in $IFACES; do
    touch /var/lib/arpwatch/arp_$IFACE.dat
    chown arpwatch.arpwatch /var/lib/arpwatch/arp_$IFACE.dat
    systemctl enable arpwatch@$IFACE.service
    systemctl start arpwatch@$IFACE.service
done

