Adblocker/create-adblock.sh

52 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2023-07-21 21:37:00 +00:00
#!/bin/bash
2023-08-08 17:33:14 +00:00
echo '' > pre-adblock.txt
touch errors.log
date=$(date '+%a, %d %b %Y %H:%M:%S %z')
#Adblock lists download
2023-08-09 17:24:37 +00:00
while read -r p; do
echo "#!MARKER- Begin of $p" >> pre-adblock.txt
2023-08-09 17:24:37 +00:00
wget -qO - "$p" >> pre-adblock.txt || echo "$date - Download failed: $p" >> errors.log
sleep 2
2023-07-21 21:37:00 +00:00
done <adblocklists.txt
# Breaking before will cause trouble if a URL is not reachable
set -u
2023-08-08 17:33:14 +00:00
#Remove comments in lists and change marker to comment
sed -i -e 's/^!.*$//g' -e 's/#!MARKER-/!MARKER-/g' pre-adblock.txt
2023-10-14 15:12:46 +00:00
echo '' > compiled/all-adblock.txt
2023-07-24 21:03:45 +00:00
2023-08-08 17:33:14 +00:00
{
#Create Header
echo '! Title: Mainboarder compiled
2023-07-21 21:37:00 +00:00
! Description: Filters optimized for uBlock, for single list use, deduplicated
2023-10-29 17:56:49 +00:00
! Expires: 1 days
2023-07-21 21:37:00 +00:00
! Last modified: '"$date"'
2023-07-24 20:48:53 +00:00
! Homepage: https://git.mainboarder.de/Public/Adblocker
2023-08-08 17:33:14 +00:00
!'
2023-07-21 21:37:00 +00:00
2023-08-08 17:33:14 +00:00
#Add own rules
cat own-rules.txt
2023-07-24 21:03:45 +00:00
2023-08-08 17:33:14 +00:00
#Remove duplicate lines
awk '!seen[$0]++' pre-adblock.txt
2023-10-14 15:12:46 +00:00
} >> compiled/all-adblock.txt
cd compiled
2024-04-26 13:51:32 +00:00
git pull --quiet
2023-10-14 15:12:46 +00:00
git add all-adblock.txt
2023-10-29 17:56:49 +00:00
git commit --quiet -m "$date"
2023-12-02 16:56:54 +00:00
git push --quiet --no-progress 2>&1 | grep -v "references"
2023-10-29 17:56:49 +00:00
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
2023-12-02 16:56:54 +00:00
git push --quiet --force --no-progress 2>&1 | grep -v "references"