diff options
author | typebrook <typebrook@gmail.com> | 2019-11-24 09:45:55 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2019-11-24 09:45:55 +0800 |
commit | f8e09e36642fa3f6e2efb04d42df79bf73e756fd (patch) | |
tree | a90da89e012dbf321774b86ade7800ae57f6c486 /scripts | |
parent | 190e26ef25942e4f355c87ce4810c2e508d1920a (diff) |
update
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/osm/osm.pbf.update | 36 |
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 @@ | |||
3 | GEOFABRICK_SERVER=http://download.geofabrik.de/asia/taiwan-updates | 3 | GEOFABRICK_SERVER=http://download.geofabrik.de/asia/taiwan-updates |
4 | PBF_FILE=$1 | 4 | PBF_FILE=$1 |
5 | 5 | ||
6 | # get next sequence number and store it into NEW_SEQ | 6 | # get latest sequence number |
7 | NEW_SEQ=$(osmium fileinfo $PBF_FILE |\ | 7 | echo Fetching latest sequence number |
8 | grep osmosis_replication_sequence_number |\ | 8 | LATEST_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 | ||
12 | SEQ=$(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 |
14 | while | 18 | while |
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" ] | ||
20 | do | 21 | do |
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++ )) | ||
33 | done | 33 | done |
34 | 34 | ||
35 | echo | 35 | echo |
36 | echo File sequence number is $((NEW_SEQ-1)), already the latest one on Geofrbrik | 36 | echo File sequence number is $((SEQ-1)), already the latest one on Geofrbrik |