#!/bin/bash

NFTABLES_CONFIG="/etc/nftables.conf"
NFTABLES_EARLY_CONFIG="/etc/nftables-early.conf"

echo "Checking if an early loading configuration '${NFTABLES_EARLY_CONFIG}' exists"
if [ -e "${NFTABLES_EARLY_CONFIG}" ] ; then
  NFTABLES_CONFIG="${NFTABLES_EARLY_CONFIG}"
fi

echo "Interfaces which are set up already: "
/usr/sbin/ip --brief link show

echo "Checking '${NFTABLES_USE_CONFIG}' for correctness"
if /usr/sbin/nft --check --file "${NFTABLES_CONFIG}" ; then
  echo "Loading '${NFTABLES_CONFIG}'"
  /usr/sbin/nft         --file "${NFTABLES_CONFIG}"
else
  echo "nft --check for '${NFTABLES_CONFIG}' failed. Not loading the config."
  exit 1
fi
