From 45ecd3877ab52d73f4bec998ad456aa270ffddac Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 23 Feb 2021 14:52:10 +0100 Subject: update --- bin/update_hosts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 bin/update_hosts (limited to 'bin/update_hosts') diff --git a/bin/update_hosts b/bin/update_hosts new file mode 100755 index 0000000..6444550 --- /dev/null +++ b/bin/update_hosts @@ -0,0 +1,16 @@ +#!/bin/sh -ex + +# Update /etc/hosts with a well curated blacklist of malware, ads, porn, etc. +# Custom hosts are preserved. + +[ "$USER" = root ] || exec sudo "$0" "$@" +cd /etc +cp -p hosts hosts.old +hosts=$(awk '/^# Custom host /, /^# End of custom host /' hosts.old) +curl -s https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts | +awk 'BEGIN { hosts = ARGV[1]; ARGV[1] = "" } +/^# Custom host / { print hosts; next } +/^# End of custom host / { next } +{print}' "$hosts" > hosts.new +mv hosts.new hosts +[ "$(uname -s)" != Darwin ] || dscacheutil -flushcache -- cgit v1.2.3 From 73aec290b0f95b7be7ef952b042359bb95b18645 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 26 Mar 2021 10:38:56 +0100 Subject: improve update_hosts --- bin/update_hosts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'bin/update_hosts') diff --git a/bin/update_hosts b/bin/update_hosts index 6444550..793344c 100755 --- a/bin/update_hosts +++ b/bin/update_hosts @@ -1,9 +1,10 @@ -#!/bin/sh -ex +#!/bin/sh -e # Update /etc/hosts with a well curated blacklist of malware, ads, porn, etc. # Custom hosts are preserved. [ "$USER" = root ] || exec sudo "$0" "$@" +echo "last update: $(date -r /etc/hosts)" cd /etc cp -p hosts hosts.old hosts=$(awk '/^# Custom host /, /^# End of custom host /' hosts.old) @@ -14,3 +15,4 @@ awk 'BEGIN { hosts = ARGV[1]; ARGV[1] = "" } {print}' "$hosts" > hosts.new mv hosts.new hosts [ "$(uname -s)" != Darwin ] || dscacheutil -flushcache +diff -u /etc/hosts.old /etc/hosts | diffstat -- cgit v1.2.3 From 9734e798057795f89a7bd0a0d933745f0d249b2f Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 26 Mar 2021 12:01:52 +0100 Subject: improve update_hosts --- bin/update_hosts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'bin/update_hosts') diff --git a/bin/update_hosts b/bin/update_hosts index 793344c..8d148a6 100755 --- a/bin/update_hosts +++ b/bin/update_hosts @@ -3,8 +3,18 @@ # Update /etc/hosts with a well curated blacklist of malware, ads, porn, etc. # Custom hosts are preserved. + [ "$USER" = root ] || exec sudo "$0" "$@" -echo "last update: $(date -r /etc/hosts)" + +echo "Check from https://github.com/StevenBlack/hosts" +lsd=$(curl -s "https://api.github.com/repos/StevenBlack/hosts/commits?path=hosts&page=1&per_page=1"| jq -r '.[0].commit.committer.date') +echo "last source update: $(date -j -f "%FT%TZ" "$lsd")" +echo "last local update: $(date -r /etc/hosts)" +if [ $(date -j -f "%FT%TZ" "$lsd" +%s) -lt $(date -r /etc/hosts +%s) ]; then + echo "Nothing to do" + exit +fi + cd /etc cp -p hosts hosts.old hosts=$(awk '/^# Custom host /, /^# End of custom host /' hosts.old) -- cgit v1.2.3 From a8243acb9f5cabd19cc9df16a15018129e0b225e Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 26 Mar 2021 13:50:43 +0100 Subject: improve update_hosts --- bin/update_hosts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'bin/update_hosts') diff --git a/bin/update_hosts b/bin/update_hosts index 8d148a6..4427cd2 100755 --- a/bin/update_hosts +++ b/bin/update_hosts @@ -10,19 +10,18 @@ echo "Check from https://github.com/StevenBlack/hosts" lsd=$(curl -s "https://api.github.com/repos/StevenBlack/hosts/commits?path=hosts&page=1&per_page=1"| jq -r '.[0].commit.committer.date') echo "last source update: $(date -j -f "%FT%TZ" "$lsd")" echo "last local update: $(date -r /etc/hosts)" -if [ $(date -j -f "%FT%TZ" "$lsd" +%s) -lt $(date -r /etc/hosts +%s) ]; then - echo "Nothing to do" - exit -fi +[ $(date -j -f "%FT%TZ" "$lsd" +%s) -lt $(date -r /etc/hosts +%s) ] && echo "Nothing to do" && exit cd /etc cp -p hosts hosts.old hosts=$(awk '/^# Custom host /, /^# End of custom host /' hosts.old) -curl -s https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts | -awk 'BEGIN { hosts = ARGV[1]; ARGV[1] = "" } -/^# Custom host / { print hosts; next } -/^# End of custom host / { next } -{print}' "$hosts" > hosts.new +curl -s 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts' | awk ' + BEGIN { hosts = ARGV[1]; ARGV[1] = "" } + /^# Custom host / { print hosts; next } + /^# End of custom host / { next } + { print } +' "$hosts" > hosts.new + mv hosts.new hosts [ "$(uname -s)" != Darwin ] || dscacheutil -flushcache diff -u /etc/hosts.old /etc/hosts | diffstat -- cgit v1.2.3 From 6962b31552fbf1a2516b0777cc4a52d99a76f6f2 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 5 May 2021 20:32:05 +0200 Subject: update --- bin/update_hosts | 1 - 1 file changed, 1 deletion(-) (limited to 'bin/update_hosts') diff --git a/bin/update_hosts b/bin/update_hosts index 4427cd2..75c41d1 100755 --- a/bin/update_hosts +++ b/bin/update_hosts @@ -3,7 +3,6 @@ # Update /etc/hosts with a well curated blacklist of malware, ads, porn, etc. # Custom hosts are preserved. - [ "$USER" = root ] || exec sudo "$0" "$@" echo "Check from https://github.com/StevenBlack/hosts" -- cgit v1.2.3 From 87b63654a7a881afefddaeb6c3dbbf32105070bb Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 4 Jun 2021 16:43:08 +0200 Subject: update, add fv --- bin/update_hosts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bin/update_hosts') diff --git a/bin/update_hosts b/bin/update_hosts index 75c41d1..e7321bf 100755 --- a/bin/update_hosts +++ b/bin/update_hosts @@ -5,7 +5,7 @@ [ "$USER" = root ] || exec sudo "$0" "$@" -echo "Check from https://github.com/StevenBlack/hosts" +echo "Checking from https://github.com/StevenBlack/hosts:" lsd=$(curl -s "https://api.github.com/repos/StevenBlack/hosts/commits?path=hosts&page=1&per_page=1"| jq -r '.[0].commit.committer.date') echo "last source update: $(date -j -f "%FT%TZ" "$lsd")" echo "last local update: $(date -r /etc/hosts)" @@ -14,7 +14,7 @@ echo "last local update: $(date -r /etc/hosts)" cd /etc cp -p hosts hosts.old hosts=$(awk '/^# Custom host /, /^# End of custom host /' hosts.old) -curl -s 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts' | awk ' +curl -s 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts' | awk ' BEGIN { hosts = ARGV[1]; ARGV[1] = "" } /^# Custom host / { print hosts; next } /^# End of custom host / { next } @@ -22,5 +22,5 @@ curl -s 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts' | aw ' "$hosts" > hosts.new mv hosts.new hosts -[ "$(uname -s)" != Darwin ] || dscacheutil -flushcache +[ "$(uname -s)" != Darwin ] || { dscacheutil -flushcache; killall -HUP mDNSResponder; } diff -u /etc/hosts.old /etc/hosts | diffstat -- cgit v1.2.3 From 2621ec5405f52343cf253d02e307c5b160cf7f04 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sun, 13 Jun 2021 14:49:53 +0200 Subject: update --- bin/update_hosts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bin/update_hosts') diff --git a/bin/update_hosts b/bin/update_hosts index e7321bf..8550ec3 100755 --- a/bin/update_hosts +++ b/bin/update_hosts @@ -13,11 +13,11 @@ echo "last local update: $(date -r /etc/hosts)" cd /etc cp -p hosts hosts.old -hosts=$(awk '/^# Custom host /, /^# End of custom host /' hosts.old) +hosts=$(awk '/^# Custom host/, /^# End of custom host/' hosts.old) curl -s 'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts' | awk ' - BEGIN { hosts = ARGV[1]; ARGV[1] = "" } - /^# Custom host / { print hosts; next } - /^# End of custom host / { next } + BEGIN { hosts = ARGV[1]; ARGV[1] = "" } + /^# Custom host/ { print hosts; next } + /^# End of custom host/ { next } { print } ' "$hosts" > hosts.new -- cgit v1.2.3 From 7a36b02b5f3ae6560030c97513b8c15d9abd16d8 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sat, 27 Nov 2021 11:04:34 +0100 Subject: update --- bin/update_hosts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bin/update_hosts') diff --git a/bin/update_hosts b/bin/update_hosts index 8550ec3..40ec470 100755 --- a/bin/update_hosts +++ b/bin/update_hosts @@ -5,11 +5,11 @@ [ "$USER" = root ] || exec sudo "$0" "$@" -echo "Checking from https://github.com/StevenBlack/hosts:" -lsd=$(curl -s "https://api.github.com/repos/StevenBlack/hosts/commits?path=hosts&page=1&per_page=1"| jq -r '.[0].commit.committer.date') +echo 'Checking from https://github.com/StevenBlack/hosts:' +lsd=$(curl -s 'https://api.github.com/repos/StevenBlack/hosts/commits?path=hosts&page=1&per_page=1' | jq -r '.[0].commit.committer.date') echo "last source update: $(date -j -f "%FT%TZ" "$lsd")" echo "last local update: $(date -r /etc/hosts)" -[ $(date -j -f "%FT%TZ" "$lsd" +%s) -lt $(date -r /etc/hosts +%s) ] && echo "Nothing to do" && exit +[ $(date -j -f "%FT%TZ" "$lsd" +%s) -lt $(date -r /etc/hosts +%s) ] && echo 'Nothing to do' && exit cd /etc cp -p hosts hosts.old -- cgit v1.2.3