summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/update_hosts12
1 files changed, 11 insertions, 1 deletions
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)