aboutsummaryrefslogtreecommitdiff
path: root/files/usr/local/libexec/idm-update-unbound-blocklists.idm_server
blob: c33b909674dee1f4be1f2790179f834dfd9e40e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh

set -eu -o pipefail

prog=$(basename "$(readlink -f "$0")")
usage="${prog} BLOCKLIST_DIR
       Blocklist URLs are read from stdin."

die() {
  printf '%s: %s\n' "$prog" "$*" 1>&2
  exit 1
}

usage(){
  printf 'usage: %s\n' "$usage" 1>&2
  exit 2
}

[ $# -eq 1 ] || usage
case $1 in
  -h|--help) usage ;;
esac

[ -d "$1" ] || die "not a directory: ${1}"

cd "$1"

find . -maxdepth 1 -type f -exec rm {} +

while read -r name url; do
  [ -n "$url" ] && curl -sSfL -o "${name}.zone" "$url"
done