summaryrefslogtreecommitdiff
path: root/bin/update_hosts
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2021-03-26 13:50:43 +0100
committerMarc Vertes <mvertes@free.fr>2021-03-26 13:50:43 +0100
commita8243acb9f5cabd19cc9df16a15018129e0b225e (patch)
tree8dfa263a3c819308fba9f7b12b69abb259503c56 /bin/update_hosts
parent9734e798057795f89a7bd0a0d933745f0d249b2f (diff)
improve update_hosts
Diffstat (limited to 'bin/update_hosts')
-rwxr-xr-xbin/update_hosts17
1 files changed, 8 insertions, 9 deletions
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