Adblocker/create-adblock.sh
2023-07-27 17:56:51 +02:00

41 lines
932 B
Bash
Executable file

#!/bin/bash
touch pre-adblock.txt
touch errors.log
date=$(date '+%a, %d %b %Y %H:%M:%S %z')
#Adblock lists download
while read p; do
echo "#!MARKER- Begin of $p" >> pre-adblock.txt
wget -qO - $p >> pre-adblock.txt
if [ $? -ne 0 ]; then
echo "$date - Download failed: $p" >> errors.log
fi
sleep 2
done <adblocklists.txt
# Breaking before will cause trouble if a URL is not reachable
set -e -u
#Remove comments in lists
sed -i 's/^!.*$//g' pre-adblock.txt
#Change marker to comment
sed -i 's/#!MARKER-/!/g' pre-adblock.txt
#Create Header
echo '! Title: Mainboarder compiled
! Description: Filters optimized for uBlock, for single list use, deduplicated
! Expires: 2 days
! Last modified: '"$date"'
! Homepage: https://git.mainboarder.de/Public/Adblocker
!' > all-adblock.txt
#Add own rules
cat own-rules.txt >> all-adblock.txt
#Remove duplicate lines
awk '!seen[$0]++' pre-adblock.txt >> all-adblock.txt