Added more output formats

This commit is contained in:
Héctor Molinero Fernández 2018-05-14 20:01:54 +02:00
commit 709e94ff46
9 changed files with 101 additions and 5 deletions

View file

@ -25,28 +25,44 @@ export DEFAULT_HOSTS
.PHONY: all \
install uninstall \
build build-hosts build-android build-windows \
build build-hosts build-domains build-adblock build-dnsmasq build-unbound build-android build-windows \
stats stats-tlds stats-suffixes \
index \
clean
all: build index
build: build-hosts build-android build-windows
build: build-hosts build-domains build-adblock build-dnsmasq build-unbound build-android build-windows
build-hosts: dist/hosts
dist/hosts:
mkdir -p dist/
"$(MKFILE_DIR)"/hblock -O dist/hosts
build-domains: build-hosts dist/hosts_domains.txt
dist/hosts_domains.txt:
"$(MKFILE_DIR)"/resources/alt-formats/domains.sh dist/hosts > dist/hosts_domains.txt
build-adblock: build-hosts dist/hosts_adblock.txt
dist/hosts_adblock.txt:
"$(MKFILE_DIR)"/resources/alt-formats/adblock.sh dist/hosts > dist/hosts_adblock.txt
build-dnsmasq: build-hosts dist/hosts_dnsmasq.conf
dist/hosts_dnsmasq.conf:
"$(MKFILE_DIR)"/resources/alt-formats/dnsmasq.sh dist/hosts > dist/hosts_dnsmasq.conf
build-unbound: build-hosts dist/hosts_unbound.conf
dist/hosts_unbound.conf:
"$(MKFILE_DIR)"/resources/alt-formats/unbound.sh dist/hosts > dist/hosts_unbound.conf
build-android: build-hosts dist/hosts_android.zip
dist/hosts_android.zip:
cd "$(MKFILE_DIR)"/resources/android/ && zip -r "$(CURDIR)"/dist/hosts_android.zip ./
cd "$(MKFILE_DIR)"/resources/alt-formats/android/ && zip -r "$(CURDIR)"/dist/hosts_android.zip ./
cd dist/ && zip -r hosts_android.zip hosts
build-windows: build-hosts dist/hosts_windows.zip
dist/hosts_windows.zip:
cd "$(MKFILE_DIR)"/resources/windows/ && zip -rl "$(CURDIR)"/dist/hosts_windows.zip ./
cd "$(MKFILE_DIR)"/resources/alt-formats/windows/ && zip -rl "$(CURDIR)"/dist/hosts_windows.zip ./
cd dist/ && zip -rl hosts_windows.zip hosts
stats: stats-tlds stats-suffixes
@ -90,6 +106,10 @@ uninstall:
clean:
rm -f \
dist/hosts \
dist/hosts_domains.txt \
dist/hosts_adblock.txt \
dist/hosts_dnsmasq.conf \
dist/hosts_unbound.conf \
dist/hosts_android.zip \
dist/hosts_windows.zip \
dist/most_abused_tlds.txt \

View file

@ -0,0 +1,19 @@
#!/bin/sh
# Author: Héctor Molinero Fernández <hector@molinero.xyz>
# Repository: https://github.com/zant95/hblock
# License: MIT, https://opensource.org/licenses/MIT
set -eu
export LC_ALL=C
main() {
hosts="${1:?}"
sed -n \
-e '/^#.*<blocklist>/,/^#.*<\/blocklist>/!d;/^\s*#.*$/d' \
-e 's/^\(.\{1,\}\)\s\{1,\}\(.\{1,\}\)\s*/||\2^/p' \
"$hosts"
}
main "$@"

View file

@ -0,0 +1,19 @@
#!/bin/sh
# Author: Héctor Molinero Fernández <hector@molinero.xyz>
# Repository: https://github.com/zant95/hblock
# License: MIT, https://opensource.org/licenses/MIT
set -eu
export LC_ALL=C
main() {
hosts="${1:?}"
sed -n \
-e '/^#.*<blocklist>/,/^#.*<\/blocklist>/!d;/^\s*#.*$/d' \
-e 's/^\(.\{1,\}\)\s\{1,\}\(.\{1,\}\)\s*/address=\/\2\/\1/p' \
"$hosts"
}
main "$@"

View file

@ -0,0 +1,19 @@
#!/bin/sh
# Author: Héctor Molinero Fernández <hector@molinero.xyz>
# Repository: https://github.com/zant95/hblock
# License: MIT, https://opensource.org/licenses/MIT
set -eu
export LC_ALL=C
main() {
hosts="${1:?}"
sed -n \
-e '/^#.*<blocklist>/,/^#.*<\/blocklist>/!d;/^\s*#.*$/d' \
-e 's/^\(.\{1,\}\)\s\{1,\}\(.\{1,\}\)\s*/\2/p' \
"$hosts"
}
main "$@"

View file

@ -0,0 +1,19 @@
#!/bin/sh
# Author: Héctor Molinero Fernández <hector@molinero.xyz>
# Repository: https://github.com/zant95/hblock
# License: MIT, https://opensource.org/licenses/MIT
set -eu
export LC_ALL=C
main() {
hosts="${1:?}"
sed -n \
-e '/^#.*<blocklist>/,/^#.*<\/blocklist>/!d;/^\s*#.*$/d' \
-e 's/^\(.\{1,\}\)\s\{1,\}\(.\{1,\}\)\s*/local-zone: "\2" redirect\nlocal-data: "\2 A \1"/p' \
"$hosts"
}
main "$@"

View file

@ -20,7 +20,7 @@ main() {
stats=''
# Get blocklist content
blocklist=$(cat -- "$file" | sed '1,/<blocklist>/d;/<\/blocklist>/,$d;')
blocklist=$(cat -- "$file" | sed '/^#.*<blocklist>/,/^#.*<\/blocklist>/!d;/^\s*#.*$/d')
# Compact blocklist content (remove lowest level domain and count ocurrences)
blocklist=$(printf -- '%s' "$blocklist" | sed 's/^.\{1,\}[[:blank:]][^.]\{1,\}//' | sort | uniq -c)