From e5f5c9b635dca0c59808c2c2aeb5b5e4d569989e Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 21 Jan 2025 15:42:22 +0100 Subject: fix bin/update_hosts --- bin/update_hosts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'bin/update_hosts') diff --git a/bin/update_hosts b/bin/update_hosts index 74bf25b..54aa528 100755 --- a/bin/update_hosts +++ b/bin/update_hosts @@ -5,13 +5,18 @@ [ "$USER" = root ] || exec sudo "$0" "$@" +cdate=date +case $(uname -s) in +(Darwin) cdate=gdate ;; # install gdate with 'brew install coreutils' +esac + 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 source update: $(date --date="$lsd")" +echo "last source update: $(date -j -f "%FT%TZ" "$lsd")" +#echo "last source update: $(date --date="$lsd")" # with BSD date 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 --date="$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 +# [ $(date --date="$lsd" +%s) -lt $(date -r /etc/hosts +%s) ] && echo 'Nothing to do' && exit # with BSD date # with BSD date cd /etc cp -p hosts hosts.old -- cgit v1.2.3