Update 2025-01-05 10:36 OpenBSD/amd64-t14
This commit is contained in:
parent
908090c41b
commit
87a300f0c4
74
.bin/update-adlist
Executable file
74
.bin/update-adlist
Executable file
@ -0,0 +1,74 @@
|
||||
#!/bin/sh -e
|
||||
|
||||
trap _restore_all 1 2 3 6
|
||||
|
||||
_list=${1:-/etc/unwind/blocklistproject.txt}
|
||||
_url=https://blocklistproject.github.io/Lists/alt-version
|
||||
_dir=/etc/unwind/lists
|
||||
|
||||
_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
|
||||
}
|
||||
_assemble() {
|
||||
echo "Assemble blocklist: /etc/unwind/_assembled.txt"
|
||||
cat $_dir/*.txt \
|
||||
| tr -d " " \
|
||||
| grep -v '^#' \
|
||||
| doas sort -uo /etc/unwind/_assembled.txt
|
||||
}
|
||||
_restart_unwind() {
|
||||
doas rcctl restart unwind
|
||||
}
|
||||
|
||||
for _file in $(grep -v "^##" $_list | xargs)
|
||||
do
|
||||
if ! _disabled $_file
|
||||
then
|
||||
_backup $_file
|
||||
_download || _restore
|
||||
fi
|
||||
done
|
||||
_assemble
|
||||
_restart_unwind
|
Loading…
Reference in New Issue
Block a user