homemade_firewall/makeconf.sh

32 lines
903 B
Bash
Executable File

#!/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