aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/osm/osm.pbf.update
blob: cd115a7cd86a5f54b28266dd7ec0500154cae462 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

GEOFABRICK_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=$GEOFABRICK_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