#!/bin/bash

. ${TOOLKIT}-functions.sh

confdir="/etc/kufirewall"

file="/etc/default/kufirewall"

if [ -f $file ]
then
	target="$file.dpkg-dist"
	[ -f "$target" ] || cp -a $file $target
	installfile "kufirewall.default" "$target" root:root 644 || exit $?
else
	installfile "kufirewall.default" "$file" root:root 644 || exit $?
fi

for i in masquerated nat redirections
do
	[ -f $confdir/$i ] || {
		installfile $i $confdir/ root:root 644 || exit $?
	}
done

rm -f $confdir/rules.d/auto-*

for name in `jtconf --listvars firewall-addrules`
do
	jtconf firewall-addrules.$name > $confdir/rules.d/auto-$name.conf
	SOMETHING_CHANGED=true
done

rm -f $confdir/masquerated.d/auto-*

for name in `jtconf --listvars firewall-masquerated`
do
	jtconf firewall-masquerated.$name > $confdir/masquerated.d/auto-$name.conf
	SOMETHING_CHANGED=true
done


$SOMETHING_CHANGED && {
	restart_service kufirewall "" || exit $?
}

# cleanup old/broken files
#
remove="
	/etc/sysctl.d/75-ku-forward-on.conf
"
uninstallfiles $remove
purgefiles $remove



exit 0
