From 6fae25b305d714b3ab7608fa003f1af9bf024545 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 14 Feb 2023 13:33:23 +0800 Subject: Rename tools into bin --- bin/osm/osm.pbf.update | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 bin/osm/osm.pbf.update (limited to 'bin/osm/osm.pbf.update') diff --git a/bin/osm/osm.pbf.update b/bin/osm/osm.pbf.update new file mode 100755 index 0000000..6c6f445 --- /dev/null +++ b/bin/osm/osm.pbf.update @@ -0,0 +1,41 @@ +#!/bin/bash + +set -e + +GEOFABRIK_SERVER=http://download.geofabrik.de/asia/taiwan-updates +PBF_FILE=$1 + +# get latest sequence number +echo Fetching the latest sequence number +LATEST_SEQ=$(curl --silent http://download.geofabrik.de/asia/taiwan-updates/state.txt |\ + tail -1 | cut -d'=' -f2) +echo Latest sequence number is $LATEST_SEQ + +# get current sequence number +SEQ=$(osmium fileinfo $PBF_FILE |\ + grep osmosis_replication_sequence_number |\ + cut -d'=' -f2) +echo File sequence number is $SEQ + +# while server has osc file with given sequence number, +# get it and do file update +while + (( SEQ++ )) + [ $SEQ -le $LATEST_SEQ ] +do + mkdir -p changes + SEQ_PATH=$(echo $SEQ | sed -r 's/(.{1})(.{3})/00\1\/\2/') + CHANGE_URL=$GEOFABRIK_SERVER/000/$SEQ_PATH.osc.gz + echo $CHANGE_URL + 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 $SEQ.osm.pbf + + mv $PBF_FILE $((SEQ-1)).osm.pbf + mv $SEQ.osm.pbf $PBF_FILE +done + +echo +echo File sequence number is $((SEQ-1)), already the latest one on Geofrbrik -- cgit v1.2.3-70-g09d2