summaryrefslogtreecommitdiff
path: root/bin/update_hosts
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2021-02-23 14:52:10 +0100
committerMarc Vertes <mvertes@free.fr>2021-02-23 14:52:10 +0100
commit29a52089c0ba2a78f5f7fa9b299f00ece9e6faf1 (patch)
tree0dacc0a2f371f48c184d9a275688c229bb1b2d37 /bin/update_hosts
parent98d3c3b82a8359d9cd1a8e5b3a6e1afe5fa56914 (diff)
update
Diffstat (limited to 'bin/update_hosts')
-rwxr-xr-xbin/update_hosts16
1 files changed, 16 insertions, 0 deletions
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