Failsafe from unreachable URLs, sed edits inline, slow download of URLs, added marker vor debugging

This commit is contained in:
Robin Kloppe 2023-07-26 15:55:30 +02:00
parent 1287de4faf
commit b9e33a9bc8
3 changed files with 22 additions and 14 deletions

2
.gitignore vendored
View file

@ -1,5 +1,5 @@
all-adblock.txt all-adblock.txt
header.txt
own-rules.txt own-rules.txt
pre-adblock.txt
.htaccess .htaccess
.htpasswd .htpasswd

View file

@ -1,8 +1,8 @@
# Anleitung # Anleitung
* `header.txt.template` umbenennen in `header.txt` * `own-rules.txt.template` umbenennen in `own-rules.txt`
* eigene Regeln einfügen (zum Beispiel aus den eigens eingesetzten Adblockern extrahieren) * eigene Regeln einfügen (zum Beispiel aus den eigens eingesetzten Adblockern extrahieren)
* die URLs zu Adblocklisten in `adblocklists.txt` anpassen * die URLs zu Adblocklisten in `adblocklists.txt` anpassen
* lokales Verzeichnis zu diesen Dateien in `create-adblock.sh:2` angeben * lokales Verzeichnis zu diesen Dateien in `create-adblock.sh:2` angeben
* Cronjob auf `create-adblock.sh` anlegen (z.B. alle zwei Tage - nicht zu oft, ob die Quelllisten nicht zu überfordern) * Cronjob auf `create-adblock.sh` anlegen (z.B. alle zwei Tage - nicht zu oft, ob die Quelllisten nicht zu überfordern)
* Skript einmalig ausführen `chmod 0744 create-adblock.sh && bash create-adblock.sh` * Skript einmalig ausführen `chmod 0744 create-adblock.sh && bash create-adblock.sh`
* Im Adblocker http(s)://URL/all-adblock.txt angeben * Im Adblocker `http(s)://URL/all-adblock.txt` angeben

View file

@ -1,27 +1,35 @@
#!/bin/bash #!/bin/bash
set -e -u
#Adblock Listen herunterladen echo "" > pre-adblock.txt
#Adblock lists download
while read p; do while read p; do
wget -qO - $p >> all-adblock.txt echo "#!MARKER- Begin of $p" >> pre-adblock.txt
wget -qO - $p >> pre-adblock.txt
sleep 2
done <adblocklists.txt done <adblocklists.txt
# Breaking before will cause trouble if a URL is not reachable
set -e -u
date=$(date '+%a, %d %b %Y %H:%M:%S %z') date=$(date '+%a, %d %b %Y %H:%M:%S %z')
#Kommentare in den Listen löschen #Remove comments in lists
sed 's/^!.*$//g' all-adblock.txt > allfilters.txt sed -i 's/^!.*$//g' pre-adblock.txt
#Header erstellen #Change marker to comment
echo '! Title: Mainboarder kompiliert sed -i 's/#!MARKER-/!/g' pre-adblock.txt
#Create Header
echo '! Title: Mainboarder compiled
! Description: Filters optimized for uBlock, for single list use, deduplicated ! Description: Filters optimized for uBlock, for single list use, deduplicated
! Expires: 2 days ! Expires: 2 days
! Last modified: '"$date"' ! Last modified: '"$date"'
! Homepage: https://git.mainboarder.de/Public/Adblocker ! Homepage: https://git.mainboarder.de/Public/Adblocker
!' > all-adblock.txt !' > all-adblock.txt
#Eigene Regeln hinzufügen #Add own rules
cat own-rules.txt >> all-adblock.txt cat own-rules.txt >> all-adblock.txt
#Duplikate entfernen #Remove duplicate lines
awk '!seen[$0]++' allfilters.txt >> all-adblock.txt awk '!seen[$0]++' pre-adblock.txt >> all-adblock.txt
rm allfilters.txt