From 419683e54d126d19720c2e6a29e3b46ace59ff59 Mon Sep 17 00:00:00 2001 From: celso Date: Fri, 13 Dec 2024 00:56:20 -0300 Subject: [PATCH] added .gitignore and a script to unify .nft files into nftables.conf --- .gitignore | 1 + makeconf.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .gitignore create mode 100755 makeconf.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8aee774 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +nftables.conf diff --git a/makeconf.sh b/makeconf.sh new file mode 100755 index 0000000..4af902e --- /dev/null +++ b/makeconf.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# ${1} is original filename +# ${2} is counter (use n for empty) +# ${3} is file to replace from +replace(){ + local pattern=$(sed ':a;N;$!ba;s/\n/Ñ/g;s/\(\/\|\.\)/\\\1/g' "${3}") + if [ ${2} != "0" ] + then + local new_content="$(sed "1,/include/{s/include \"[a-z\.\/]\+\"/${pattern}/}" "${1}""$(bc -l <<< "${2} - 1")".nft | sed 's/Ñ/\n/g')"; + echo "${new_content}" > "${1}${2}".nft + else + local new_content="$(sed "1,/include/{s/include \"[a-z\.\/]\+\"/${pattern}/}" "${1}".nft | sed 's/Ñ/\n/g')"; + echo "${new_content}" > "${1}${2}".nft + fi +} + +filename=filter +declare -i counter=0 +for i in $(grep include filter.nft | awk '{print $2}' | tr -d \") + do replace "${filename}" "${counter}" "${i}" + counter+=1 +done + +counter=${counter}-1 +mv "${filename}""${counter}".nft nftables.conf +while [ ${counter} -ge 0 ] +do + rm "${filename}""${counter}".nft + counter=${counter}-1 +done