#!/bin/bash
set -e

bak="--backup=numbered"
sed -e '/^#/d' -e '/^$/d'  /etc/dnsmasq.conf | grep . && mv $bak /etc/dnsmasq.conf /etc/dnsmasq.conf.dpkg-old
sed -i -e 's?^CONFIG_DIR=.*$?CONFIG_DIR=/etc/dnsmasq.d,\*.conf?' /etc/default/dnsmasq
[[ ! -f /etc/nftables.conf || "$(readlink /etc/nftables.conf)" == /etc/omix/conf/nftables.conf ]] || \
  mv $bak /etc/nftables.conf /etc/nftables.conf.dpkg-old

/usr/share/omix/mkconf.gw

for f in dhcp.conf dnsmasq.conf servers; do
  [ -L /etc/dnsmasq.d/$f ] || ln -s /etc/omix/conf/$f /etc/dnsmasq.d/$f
done
[ -L /etc/nftables.conf ] || ln -s /etc/omix/conf/nftables.conf /etc/nftables.conf

systemctl restart dnsmasq
systemctl restart nftables


