maza-ad-blocking/maza
2020-01-03 09:50:01 +01:00

87 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# START
set -e
PROGNAME=$(basename $0)
CONFIG=($HOME/.maza/)
LIST="list"
START_TAG="## MAZA - List ad blocking"
END_TAG="## END MAZA"
# FUNCTIONS
## HELP
usage() {
if [ "$*" != "" ] ; then
echo "Error: $*"
fi
cat << EOF
Usage: $PROGNAME [OPTION]
Simple and efficient local ad blocking throughout the network.
Options:
update Update the list of DNS to be blocked
start Activate blocking DNS.
stop Stop blocking DNS.
--help Display this usage message and exit
EOF
exit 1
}
## UPDATE
update() {
# Make conf folder
rm -f $CONFIG/$LIST
mkdir -p $CONFIG
# Download DNS list
curl -L -s "https://pgl.yoyo.org/adservers/serverlist.php?showintro=0;hostformat=hosts" -o "$CONFIG/$LIST"
# Clear list
## Get PRE tag
sed -i .bak -n "/<pre>/,/<\/pre>/p" "$CONFIG/$LIST"
## Remove first line
sed -i .bak '1d' "$CONFIG/$LIST"
## Remove last line
sed -i .bak '$ d' "$CONFIG/$LIST"
## Add start tag DNS list in first line
sed -i .bak "1i\\
$START_TAG
" "$CONFIG/$LIST"
## Add end tag DNS list in first line
echo $END_TAG >> "$CONFIG/$LIST"
# Notify user
echo "Done!"
}
# CONTROLE ARGUMENTS
isArg=""
while [ $# -gt 0 ] ; do
case "$1" in
--help)
usage
;;
update)
isArg="1"
update
;;
start)
echo "Start"
isArg="1"
;;
stop)
echo "Stop"
isArg="1"
;;
*)
esac
shift
done
if [ -z $isArg ] ; then
usage "Not enough arguments"
fi