/youtube.sh

https://github.com/kboghdady/youTube_ads_4_pi-hole · Shell · 58 lines · 22 code · 17 blank · 19 comment · 4 complexity · 17cac3ea87486bcc13c8115b91bbe444 MD5 · raw file

  1. #!/bin/sh
  2. # Update the pihole list with youtube ads
  3. # this shell script is made by Kiro
  4. #Thank you for using it and enjoy
  5. # The script will create a file with all the youtube ads found in hostsearch and from the logs of the Pi-hole
  6. # it will append the list into a file called blacklist.txt'/etc/pihole/blacklist.txt'
  7. piholeIPV4=$(hostname -I |awk '{print $1}')
  8. piholeIPV6=$(hostname -I |awk '{print $2}')
  9. # This need to be chnaged to your actual repo dir on your machine
  10. repoDir='/pi/youTube_ads_4_pi-hole'
  11. blackListFile='/etc/pihole/black.list'
  12. blacklist='/etc/pihole/blacklist.txt'
  13. # Get the list from the GitHub
  14. sudo curl 'https://raw.githubusercontent.com/kboghdady/youTube_ads_4_pi-hole/master/black.list'\
  15. >>$blacklist
  16. sudo curl 'https://raw.githubusercontent.com/kboghdady/youTube_ads_4_pi-hole/master/black.list'\
  17. >>$blackListFile
  18. #Enable if you want to include the list added by the crowed
  19. #sudo curl 'https://raw.githubusercontent.com/kboghdady/youTube_ads_4_pi-hole/master/crowed_list.txt'\
  20. #>>$blackListFile
  21. wait
  22. # check to see if gawk is installed. if not it will install it
  23. dpkg -l | grep -qw gawk || sudo apt-get install gawk -y
  24. # remove the domains from the ignore.list
  25. while read line ; do sed -i "/.*$line.*/d" $repoDir/youtubelist.txt ; done < $repoDir/ignore.list
  26. while read line ; do sed -i "/.*$line.*/d" $repoDir/black.list ; done < $repoDir/ignore.list
  27. wait
  28. # remove the duplicate records in place
  29. gawk -i inplace '!a[$0]++' $blackListFile
  30. wait
  31. gawk -i inplace '!a[$0]++' $blacklist
  32. # this in case you have an old blocked domain the the database
  33. while read ignoredDns ; do /usr/bin/sqlite3 /etc/pihole/gravity.db "delete from domainlist where domain like '%$ignoredDns%' " ; done < ignore.list
  34. ## adding it to the blacklist in Pihole V5
  35. # only 200 Domains at once
  36. sudo xargs -a $blacklist -L200 pihole -b -nr
  37. # restart dns
  38. sudo pihole restartdns
  39. #### only disable if you don't like to share your youtube logs to be be added to my list
  40. sharedlogs=`sudo /usr/bin/sqlite3 /etc/pihole/pihole-FTL.db "select domain from queries where domain like '%googlevideo.com'" |uniq -d |tr '\n' ','`
  41. curl -sL "https://docs.google.com/forms/d/e/1FAIpQLSd_j3lQs_B7S3Hz3aA3IkwYMF4my0DnBMZFAn3e9grZo61VFQ/formResponse?usp=pp_url&entry.275594062=$sharedlogs"