#!/bin/sh -e trap _restore_all 1 2 3 6 # list of filenames can can be fetched from $_url _list=/etc/unwind/blocklistproject.txt _url=https://blocklistproject.github.io/Lists/alt-version # download blocklists here _dir=/etc/unwind/lists # combined, sorted and filtered list of all lists configured in $_list # configure in /etc/unwind.conf: # block list "/etc/unwind/_assembled.txt" log _unwind_blocklist="/etc/unwind/_assembled.txt" if [ ! -f $_list ] then echo "Creating new adlist /etc/unwind/blocklistproject.txt:" doas mkdir -p $_dir doas tee $_list < comment ## # => disabled list (will be deleted if present) abuse-nl.txt adobe-nl.txt ads-nl.txt basic-nl.txt crypto-nl.txt drugs-nl.txt #everything-nl.txt facebook-nl.txt fortnite-nl.txt fraud-nl.txt gambling-nl.txt malware-nl.txt phishing-nl.txt piracy-nl.txt porn-nl.txt ransomware-nl.txt redirect-nl.txt scam-nl.txt smart-tv-nl.txt tiktok-nl.txt torrent-nl.txt tracking-nl.txt twitter-nl.txt vaping-nl.txt whatsapp-nl.txt youtube-nl.txt EOF fi _restore_all() { echo "Signal received, aborting..." for _f in $_dir/*.old do echo "Restore: $(basename $_f)" doas mv -f "$_f" "${_f%%.old}" done _assemble _restart_unwind exit 1 } _backup() { _f=$(basename "$1") if [ -f "$_dir/$_f" ] then echo "Backup: $_f -> $_f.old" doas mv -f "$_dir/$_f" "$_dir/$_f.old" fi } _restore() { _f=$(basename "$1") if [ -f "$_dir/$_f.old" ] then echo "Restore: $_f.old -> $_f" doas mv -f "$_dir/$_f" "$_dir/$_f.old" fi } _download() { echo "Download: $_file" doas ftp -V -o "$_dir/$_file" "$_url/$_file" > /dev/null \ && doas rm -f "$_dir/$_file.old" } _disabled() { if echo "$1" | grep -q "^#" then _f=$(basename "$1" | tr -d '# ') echo "Skip (disabled): $_f" doas rm -f $_dir/$_f return 0 fi return 1 } _domainfilter() { # chain grep commands used in assemble pipe grep -Ev "torrent|instagram\.com|tattoo|whatsapp\.com" } _assemble() { echo "Assemble blocklist: $_unwind_blocklist" cat $_dir/*.txt \ | tr -d " " \ | grep -v '^#' \ | grep -v '^-' \ | grep -v '^$' \ | cut -d "#" -f1 \ | sed 's/\.$//g' \ | _domainfilter \ | doas sort -uo $_unwind_blocklist } _restart_unwind() { doas rcctl restart unwind } for _file in $(grep -v "^##" $_list \ | cut -d "#" -f1 \ | xargs) do if ! _disabled $_file then _backup $_file _download || _restore fi done _assemble _restart_unwind