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