diff options
Diffstat (limited to 'bin/osm/osm.pbf.update')
-rwxr-xr-x | bin/osm/osm.pbf.update | 41 |
1 files changed, 41 insertions, 0 deletions
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 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | GEOFABRIK_SERVER=http://download.geofabrik.de/asia/taiwan-updates | ||
6 | PBF_FILE=$1 | ||
7 | |||
8 | # get latest sequence number | ||
9 | echo Fetching the latest sequence number | ||
10 | LATEST_SEQ=$(curl --silent http://download.geofabrik.de/asia/taiwan-updates/state.txt |\ | ||
11 | tail -1 | cut -d'=' -f2) | ||
12 | echo Latest sequence number is $LATEST_SEQ | ||
13 | |||
14 | # get current sequence number | ||
15 | SEQ=$(osmium fileinfo $PBF_FILE |\ | ||
16 | grep osmosis_replication_sequence_number |\ | ||
17 | cut -d'=' -f2) | ||
18 | echo File sequence number is $SEQ | ||
19 | |||
20 | # while server has osc file with given sequence number, | ||
21 | # get it and do file update | ||
22 | while | ||
23 | (( SEQ++ )) | ||
24 | [ $SEQ -le $LATEST_SEQ ] | ||
25 | do | ||
26 | mkdir -p changes | ||
27 | SEQ_PATH=$(echo $SEQ | sed -r 's/(.{1})(.{3})/00\1\/\2/') | ||
28 | CHANGE_URL=$GEOFABRIK_SERVER/000/$SEQ_PATH.osc.gz | ||
29 | echo $CHANGE_URL | ||
30 | curl -o changes/$SEQ.osc.gz $CHANGE_URL && \ | ||
31 | osmium apply-changes $PBF_FILE changes/$SEQ.osc.gz \ | ||
32 | --output-header=osmosis_replication_sequence_number=$SEQ \ | ||
33 | --overwrite \ | ||
34 | --output $SEQ.osm.pbf | ||
35 | |||
36 | mv $PBF_FILE $((SEQ-1)).osm.pbf | ||
37 | mv $SEQ.osm.pbf $PBF_FILE | ||
38 | done | ||
39 | |||
40 | echo | ||
41 | echo File sequence number is $((SEQ-1)), already the latest one on Geofrbrik | ||