blockliste/update-list.sh

45 lines
887 B
Bash
Executable file

#!/bin/sh
TYPE="always-null"
CONFDIR="/etc/unbound"
CONFFILE="${TYPE}.conf"
CONF="${CONFDIR}/${CONFFILE}"
SOURCES="${CONFDIR}/sources"
BUILDDIR="$(openssl rand -hex 42)"
cleanup()
{
cd /tmp || cd || true
rm -r "${BUILDDIR}"
}
update_sources()
{
mkdir -p "/tmp/${BUILDDIR}" && cd "/tmp/${BUILDDIR}" || exit 1
cat "${SOURCES}" | while read -r src
do
curl -#LO "${src}"
done
find . -type f | while read -r file
do
cat "${file}" | tee -a domains
done
}
format_sources()
{
cat domains | tr -d '|' | tr -d '^' | grep -v '#' | sed -e 's|0.0.0.0 ||g' | sort -u | uniq > new_domains
cat new_domains | while read -r domain
blocktype="$(printf '%b' "${TYPE}" | sed -e 's|-|_|g')"
do
if ! [ -z "${domain}" ]
then
printf 'local-zone: "%b" %b\n' "${domain}" "${blocktype}"
fi
done | uniq | tee "${CONF}"
}
trap cleanup QUIT INT TERM EXIT
update_sources
format_sources