adapting to work with both mac and linux

This commit is contained in:
robocopAlpha 2021-07-15 11:39:45 +03:00
parent 2baf1d1de7
commit daa48b1ced
4 changed files with 102 additions and 64 deletions

View file

@ -1,22 +1,11 @@
#!/usr/bin/env bash
[[ -f set_env.sh ]] && source set_env.sh || { echo "set_env.sh not found"; exit 1; }
# Going to the right path
WRK_DIR=/home/dietpi/pihole_lists/Mirrors
mkdir ${WRK_DIR}
cd ${WRK_DIR}
fetch_hosts(){
URL=$1
FNAME=$2
curl -sSL "${URL}" | rg -INv "^[#]|localhost" | sd '\s+$' '' | sd "^0\\.0\\.0\\.0 |^127\\.0\\.0\\.1 " "" | sd "\\#.*" "" >| ${FNAME}
}
fetch_blocklist(){
URL=$1
FNAME=$2
curl -sSL "${URL}" | rg -INv "^[#]|localhost" | sd '\s+$' '' | sd "\\#.*" "" >| ${FNAME}
}
WRK_DIR="${WRK_DIR}/Mirrors"
mkdir "${WRK_DIR}"
cd "${WRK_DIR}"
if ping -c 1 -W 2 www.google.fi &> /dev/null ; then
echo " Fetching lists. Please wait..."
@ -69,10 +58,10 @@ if ping -c 1 -W 2 www.google.fi &> /dev/null ; then
# Steven Black's list needs some extra clean up
curl -sSL 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts' >| 'tmp.txt'
rg --after-context $(wc -l ${WRK_DIR}/tmp.txt | awk {'print $1'}) "^# Start StevenBlack" ${WRK_DIR}/tmp.txt >| ${WRK_DIR}/tmp2.txt
rm -f ${WRK_DIR}/tmp.txt
rg -FINv "#" ${WRK_DIR}/tmp2.txt | sort -u | uniq >| ${WRK_DIR}/StevenBlack.txt
rm -f ${WRK_DIR}/tmp2.txt
rg --after-context $(wc -l tmp.txt | awk {'print $1'}) "^# Start StevenBlack" tmp.txt >| tmp2.txt
rm -f tmp.txt
rg -FINv "#" tmp2.txt | sort -u | uniq >| StevenBlack.txt
rm -f tmp2.txt
#--------
echo " #Lines FileName"
wc -l *.txt