#!/bin/sh # # Copyright (c) 2021 Gregory L. Dietsche # This is free software, licensed under the MIT License # HasIpAddressChanged() { # Create a sorted, unique list of addresses using DNS HOST_LIVE=$(nslookup "$1" | grep "Address\ [0-9]\+:" | sed -r 's/^Address [0-9]+: //' | sort | uniq -i) # Create a sorted, unique list of addresess currently in use HOST_SAFE=$(grep -i "^[:0-9a-f]" "$2" | sed 's/ .*//' | sort | uniq -i) # dns resolution errors / not being connected to the internet can cause this. if [ -z "$HOST_LIVE" ]; then return 1 fi #If the lists do not match, then we want to update to match the DNS records. if [ "$HOST_LIVE" = "$HOST_SAFE" ]; then return 1 # IP has NOT changed fi return 0 # IP has changed } StartIpAddressUpdate(){ echo Updating "$1" RELOAD_DNSMASQ=1 #Create the new hosts file... cat >"$1"<>$HOST_FILE fi ################################################# ### safe.duckduckgo.com ### ################################################# HOST_FILE=/etc/safe-search/available/duckduckgo.default if HasIpAddressChanged safe.duckduckgo.com $HOST_FILE; then StartIpAddressUpdate $HOST_FILE MakeHost "duckduckgo.com">>$HOST_FILE fi ################################################# ### restrict.youtube.com ### ################################################# HOST_FILE=/etc/safe-search/available/youtube.restrict if HasIpAddressChanged restrict.youtube.com $HOST_FILE; then StartIpAddressUpdate $HOST_FILE MakeHost "www.youtube.com m.youtube.com youtubei.googleapis.com youtube.googleapis.com www.youtube-nocookie.com">>$HOST_FILE fi ################################################# ### restrictmoderate.youtube.com ### ################################################# HOST_FILE=/etc/safe-search/available/youtube.restrictmoderate if HasIpAddressChanged restrictmoderate.youtube.com $HOST_FILE; then StartIpAddressUpdate $HOST_FILE MakeHost "www.youtube.com m.youtube.com youtubei.googleapis.com youtube.googleapis.com www.youtube-nocookie.com">>$HOST_FILE fi ################################################# ### forcesafesearch.google.com ### ### https://www.google.com/supported_domains ### ################################################# HOST_FILE=/etc/safe-search/available/google.default if HasIpAddressChanged forcesafesearch.google.com $HOST_FILE; then StartIpAddressUpdate $HOST_FILE cat >>"$HOST_FILE"<