aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/osm/osm.pbf.update36
1 files changed, 18 insertions, 18 deletions
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 @@
3GEOFABRICK_SERVER=http://download.geofabrik.de/asia/taiwan-updates 3GEOFABRICK_SERVER=http://download.geofabrik.de/asia/taiwan-updates
4PBF_FILE=$1 4PBF_FILE=$1
5 5
6# get next sequence number and store it into NEW_SEQ 6# get latest sequence number
7NEW_SEQ=$(osmium fileinfo $PBF_FILE |\ 7echo Fetching latest sequence number
8 grep osmosis_replication_sequence_number |\ 8LATEST_SEQ=$(curl --silent http://download.geofabrik.de/asia/taiwan-updates/state.txt |\
9 cut -d'=' -f2 |\ 9 tail -1 | cut -d'=' -f2)
10 sed 's/$/+1/' | bc) 10
11# get current sequence number
12SEQ=$(osmium fileinfo $PBF_FILE |\
13 grep osmosis_replication_sequence_number |\
14 cut -d'=' -f2)
11 15
12# while server has osc file with given sequence number, 16# while server has osc file with given sequence number,
13# get it and do file update 17# get it and do file update
14while 18while
15 SEQ_PATH=$(echo $NEW_SEQ | sed -r 's/(.{1})(.{3})/00\1\/\2/') 19 (( SEQ++ ))
16 STATE_URL=$GEOFABRICK_SERVER/000/$SEQ_PATH.state.txt 20 [ $SEQ -le $LATEST_SEQ ]
17 echo check state file exists:
18 echo $STATE_URL
19 [ $(curl -o /dev/null --silent -Iw "%{http_code}" $STATE_URL) != "404" ]
20do 21do
21 mkdir -p changes 22 mkdir -p changes
22 CHANGE_URL=$GEOFABRICK_SERVER/000/$SEQ_PATH.osc.gz 23 CHANGE_URL=$GEOFABRICK_SERVER/000/$SEQ_PATH.osc.gz
23 echo $CHANGE_URL 24 echo $CHANGE_URL
24 curl -o changes/$NEW_SEQ.osc.gz $CHANGE_URL && \ 25 curl -o changes/$SEQ.osc.gz $CHANGE_URL && \
25 osmium apply-changes $PBF_FILE changes/$NEW_SEQ.osc.gz \ 26 osmium apply-changes $PBF_FILE changes/$SEQ.osc.gz \
26 --output-header=osmosis_replication_sequence_number=$NEW_SEQ \ 27 --output-header=osmosis_replication_sequence_number=$SEQ \
27 --overwrite \ 28 --overwrite \
28 --output $NEW_SEQ.osm.pbf 29 --output $SEQ.osm.pbf
29 30
30 mv $PBF_FILE $((NEW_SEQ-1)).osm.pbf 31 mv $PBF_FILE $((SEQ-1)).osm.pbf
31 mv $NEW_SEQ.osm.pbf $PBF_FILE 32 mv $SEQ.osm.pbf $PBF_FILE
32 (( NEW_SEQ++ ))
33done 33done
34 34
35echo 35echo
36echo File sequence number is $((NEW_SEQ-1)), already the latest one on Geofrbrik 36echo File sequence number is $((SEQ-1)), already the latest one on Geofrbrik