Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3.7 #13

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions ytadsblocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This script was made in order to block all the Youtube's advertisement in Pi-Hole

YTADSBLOCKER_VERSION="3.6"
YTADSBLOCKER_VERSION="3.7"
YTADSBLOCKER_LOG="/var/log/ytadsblocker.log"
YTADSBLOCKER_GIT="https://raw.githubusercontent.com/deividgdt/ytadsblocker/master/ytadsblocker.sh"
VERSIONCHECKER_TIME="280"
Expand All @@ -17,6 +17,7 @@ SCRIPT_NAME=$(basename $0)
PRINTWD=$(pwd)
SQLITE3BIN=$(whereis -b sqlite3 | cut -f 2 -d" ")
TEMPDIR="/tmp/ytadsblocker"
CONFIGFILE="/etc/pihole/.ytadsblocker.cfg"
DOCKER_PIHOLE="/etc/docker-pi-hole-version"
ROOT_UID=0
NORMALPATTERN='r([0-9]{1,2})[^-].*\.googlevideo\.com'
Expand Down Expand Up @@ -120,6 +121,16 @@ function Database() {
esac
}

function LoadConfiguration(){
# We check if the file exists
if [ -f ${CONFIGFILE} ]; then

# First we get the pattern chosen by the user
export PATTERN=$(grep 'current_pattern' ${CONFIGFILE} | cut -f 2 -d'=')

fi
}



function Install() {
Expand All @@ -135,12 +146,15 @@ function Install() {
case $answer in
Y|y)
PATTERN=${AGGRESSIVEPATTERN}
echo "current_pattern=${PATTERN}" >> ${CONFIGFILE}
;;
N|n)
PATTERN=${NORMALPATTERN}
echo "current_pattern=${PATTERN}" >> ${CONFIGFILE}
;;
*)
PATTERN=${NORMALPATTERN}
echo "current_pattern=${PATTERN}" >> ${CONFIGFILE}
;;
esac

Expand Down Expand Up @@ -210,9 +224,10 @@ function Install() {
}

function Start() {

CheckUser #We check if the root user is executing the script

LoadConfiguration #We load the main configuration from the file ${CONFIGFILE}

echo "Youtube Ads Blocker Started"
echo "Check the $YTADSBLOCKER_LOG file to get further information."

Expand Down Expand Up @@ -302,6 +317,11 @@ function Uninstall() {
fi
fi

if [ -f ${CONFIGFILE} ]; then
echo -e "${TAGINFO} Deleting config file..."
rm --force ${CONFIGFILE}
fi

echo -e "${TAGOK} YouTube Ads Blocker Uninstalled. Bye"
kill -9 `pgrep ytadsblocker`

Expand All @@ -323,3 +343,4 @@ case "$1" in
"uninstall" ) Uninstall ;;
* ) echo "That option does not exists. Usage: ./$SCRIPT_NAME [ install | start | stop | uninstall ]";;
esac