From f8e09e36642fa3f6e2efb04d42df79bf73e756fd Mon Sep 17 00:00:00 2001 From: typebrook Date: Sun, 24 Nov 2019 09:45:55 +0800 Subject: update --- scripts/osm/osm.pbf.update | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'scripts') diff --git a/scripts/osm/osm.pbf.update b/scripts/osm/osm.pbf.update index 9dec41c..8c10d5b 100755 --- a/scripts/osm/osm.pbf.update +++ b/scripts/osm/osm.pbf.update @@ -3,34 +3,34 @@ GEOFABRICK_SERVER=http://download.geofabrik.de/asia/taiwan-updates PBF_FILE=$1 -# get next sequence number and store it into NEW_SEQ -NEW_SEQ=$(osmium fileinfo $PBF_FILE |\ - grep osmosis_replication_sequence_number |\ - cut -d'=' -f2 |\ - sed 's/$/+1/' | bc) +# get latest sequence number +echo Fetching latest sequence number +LATEST_SEQ=$(curl --silent http://download.geofabrik.de/asia/taiwan-updates/state.txt |\ + tail -1 | cut -d'=' -f2) + +# get current sequence number +SEQ=$(osmium fileinfo $PBF_FILE |\ + grep osmosis_replication_sequence_number |\ + cut -d'=' -f2) # while server has osc file with given sequence number, # get it and do file update while - SEQ_PATH=$(echo $NEW_SEQ | sed -r 's/(.{1})(.{3})/00\1\/\2/') - STATE_URL=$GEOFABRICK_SERVER/000/$SEQ_PATH.state.txt - echo check state file exists: - echo $STATE_URL - [ $(curl -o /dev/null --silent -Iw "%{http_code}" $STATE_URL) != "404" ] + (( SEQ++ )) + [ $SEQ -le $LATEST_SEQ ] do mkdir -p changes CHANGE_URL=$GEOFABRICK_SERVER/000/$SEQ_PATH.osc.gz echo $CHANGE_URL - curl -o changes/$NEW_SEQ.osc.gz $CHANGE_URL && \ - osmium apply-changes $PBF_FILE changes/$NEW_SEQ.osc.gz \ - --output-header=osmosis_replication_sequence_number=$NEW_SEQ \ + curl -o changes/$SEQ.osc.gz $CHANGE_URL && \ + osmium apply-changes $PBF_FILE changes/$SEQ.osc.gz \ + --output-header=osmosis_replication_sequence_number=$SEQ \ --overwrite \ - --output $NEW_SEQ.osm.pbf + --output $SEQ.osm.pbf - mv $PBF_FILE $((NEW_SEQ-1)).osm.pbf - mv $NEW_SEQ.osm.pbf $PBF_FILE - (( NEW_SEQ++ )) + mv $PBF_FILE $((SEQ-1)).osm.pbf + mv $SEQ.osm.pbf $PBF_FILE done echo -echo File sequence number is $((NEW_SEQ-1)), already the latest one on Geofrbrik +echo File sequence number is $((SEQ-1)), already the latest one on Geofrbrik -- cgit v1.2.3-70-g09d2