blockliste/update-list.sh

46 lines
870 B
Bash
Raw Normal View History

2024-12-26 11:58:21 +01:00
#!/bin/sh
2024-12-30 18:07:32 +01:00
TYPE="always-null"
2024-12-26 11:58:21 +01:00
CONFDIR="/etc/unbound"
2024-12-30 18:07:32 +01:00
CONFFILE="${TYPE}.conf"
2024-12-26 11:58:21 +01:00
CONF="${CONFDIR}/${CONFFILE}"
SOURCES="${CONFDIR}/sources"
BUILDDIR="$(openssl rand -hex 42)"
cleanup()
{
cd /tmp || cd || true
rm -r "${BUILDDIR}"
}
2024-12-26 11:58:21 +01:00
update_sources()
{
mkdir -p "/tmp/${BUILDDIR}" && cd "/tmp/${BUILDDIR}" || exit 1
2024-12-26 11:58:21 +01:00
cat "${SOURCES}" | while read -r src
do
curl -#LO "$src"
done
find . -type f | while read -r file
do
cat "${file}" | tee -a domains
2024-12-26 11:58:21 +01:00
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
2024-12-30 18:07:32 +01:00
blocktype="$(printf '%b' "$TYPE" | sed -e 's|-|_|g')"
2024-12-26 11:58:21 +01:00
do
if ! [ -z "$domain" ]
then
2024-12-30 18:07:32 +01:00
printf 'local-zone: "%b" %b\n' "$domain" "$blocktype"
2024-12-26 11:58:21 +01:00
fi
done | tee "${CONF}"
}
trap cleanup QUIT INT TERM EXIT
2024-12-26 11:58:21 +01:00
update_sources
format_sources