#!/bin/sh
CONF=/etc/dnsthingy/dnsthingymgr.conf
interfaces=/etc/sysconfig/network-scripts/ifcfg-*:*

# Allow ClearSync to access check script
LINE=`grep "^Cmnd_Alias CLEARSYNC" /etc/sudoers 2>/dev/null`
STATUS=`echo $LINE | grep /etc/dnsthingy/status`
if [ -z "$STATUS" ]; then
    sed -i '\|^Cmnd_Alias CLEARSYNC =| s|$|, /etc/dnsthingy/status|' /etc/sudoers
fi

# Remove old sudoer modification
sed -i '\|^Cmnd_Alias CLEARSYNC =| s|, /etc/dnsthingy/check||' /etc/sudoers

# Restart clearsync
/sbin/service clearsync restart >/dev/null 2>&1

# Verify all DNSthingy data and configuration
echo "Setting up. This may take a few minutes..."
[ -x /etc/dnsthingy/status ] && /etc/dnsthingy/status fix >/dev/null 2>&1

# Restart the firewall
service firewall restart >/dev/null 2>&1

# Remove an old chkconfig file. Cleanup added in app-dnsthingy 1.4 (2016-03)
#   Left behind by dnsthingy package < 1.8 (includes app binary 3.1.4)
chkconfig --del dnsthingy >/dev/null 2>&1

echo "Visit the ClearOS config page to activate."
