From 4048945e110ef0f373ab890e25af7a7d1dac21a9 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 12 Feb 2015 06:11:17 +0100 Subject: [PATCH] browser: wget-ifmodified script to download new caniuse data --- Makefile | 3 +++ tools/wget-ifmodified | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 tools/wget-ifmodified diff --git a/Makefile b/Makefile index d7c1003..4e51768 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ data/countryInfo.txt: countries.inc.pl: data/countryInfo.txt tools/mkcountries-geonames data/countryInfo.txt >$@ +data/caniuse.json: + tools/wget-ifmodified http://caniuse.com/data.json $@ + clean: -rm digraphs.inc.pl -rm unicode-char.inc.pl diff --git a/tools/wget-ifmodified b/tools/wget-ifmodified new file mode 100755 index 0000000..bae00f1 --- /dev/null +++ b/tools/wget-ifmodified @@ -0,0 +1,26 @@ +#!/usr/bin/env sh + +set -u + +if [ -z "$1" ] +then + echo 'Usage: $0 []' >&2 + # download url to target location if modified + exit 64 # EX_USAGE +fi + +source=$1 +target=${2:-${source##*/}} + +if [ -e "$target" ] +then + modified=$(stat -c%y -L "$target") && + modified=$(date -R -d "$modified") + echo download since: $modified +fi + +headers=${modified:+If-Modified-Since: $modified} +wget -nv --header="$headers" -O "$target.new" "$source" && +mv "$target.new" "$target" || +rm "$target.new" # clean up failed download (usually empty 304 response) + -- 2.30.0