diff options
Diffstat (limited to 'bin/update_hosts')
| -rwxr-xr-x | bin/update_hosts | 13 |
1 files changed, 9 insertions, 4 deletions
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 |
