diff options
| author | Marc Vertes <mvertes@free.fr> | 2021-03-26 12:01:52 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2021-03-26 12:01:52 +0100 |
| commit | 9734e798057795f89a7bd0a0d933745f0d249b2f (patch) | |
| tree | d3172288a747657f5272d96c25ae16cb84f3f4ff | |
| parent | 73aec290b0f95b7be7ef952b042359bb95b18645 (diff) | |
improve update_hosts
| -rwxr-xr-x | bin/update_hosts | 12 |
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) |
