Adblocker/create-adblock.sh

52 lines
1.3 KiB
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 -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: 1 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 pull --quiet
git add all-adblock.txt
git commit --quiet -m "$date"
git push --quiet --no-progress 2>&1 | grep -v "references"
lastcommit=$(git log --pretty=format:'%H' -n 3 | tail -n 1)
git checkout --quiet --orphan temp $lastcommit
git commit --quiet -m "Truncated history"
git rebase --quiet --onto temp $lastcommit main
git branch --quiet -D temp
git push --quiet --force --no-progress 2>&1 | grep -v "references"