Adblocker/create-adblock.sh

44 lines
1,018 B
Bash
Executable file

#!/bin/bash
echo '' > pre-adblock.txt
touch errors.log
date=$(date '+%a, %d %b %Y %H:%M:%S %z')
#Adblock lists download
while read -r p; do
echo "#!MARKER- Begin of $p" >> pre-adblock.txt
wget -qO - "$p" >> pre-adblock.txt || echo "$date - Download failed: $p" >> errors.log
sleep 2
done <adblocklists.txt
# Breaking before will cause trouble if a URL is not reachable
set -e -u
#Remove comments in lists and change marker to comment
sed -i -e 's/^!.*$//g' -e 's/#!MARKER-/!MARKER-/g' pre-adblock.txt
echo '' > compiled/all-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
!'
#Add own rules
cat own-rules.txt
#Remove duplicate lines
awk '!seen[$0]++' pre-adblock.txt
} >> compiled/all-adblock.txt
cd compiled
git add all-adblock.txt
git commit -m "$date" > /dev/null
git push > /dev/null 2>&1