1
1
#! /usr/bin/env bash
2
+ export VOLUME_DIR=/mnt/data
3
+ export PGPASSWORD=$POSTGRES_PASSWORD
2
4
3
5
# OSMOSIS tuning: https://wiki.openstreetmap.org/wiki/Osmosis/Tuning,https://lists.openstreetmap.org/pipermail/talk/2012-October/064771.html
4
6
if [ -z " $MEMORY_JAVACMD_OPTIONS " ]; then
7
9
memory=" ${MEMORY_JAVACMD_OPTIONS// i} "
8
10
echo JAVACMD_OPTIONS=\" -server -Xmx$memory \" > ~ /.osmosis
9
11
fi
12
+
10
13
# Get the data
11
- wget $URL_FILE_TO_IMPORT
12
14
file=$( basename $URL_FILE_TO_IMPORT )
15
+ osmFile=$VOLUME_DIR /$file
16
+ [ ! -f $osmFile ] && wget $URL_FILE_TO_IMPORT
13
17
14
18
function importData () {
19
+ # This is using a osmosis 0.47. TODO: test with osmosis 0.48, and remove the following line
20
+ psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c " ALTER TABLE users ADD COLUMN nearby VARCHAR;"
15
21
# In case the import file is a PBF
16
- if [ ${file : -4} == " .pbf" ]; then
17
- pbfFile=$file
22
+ if [ ${osmFile : -4} == " .pbf" ]; then
23
+ pbfFile=$osmFile
18
24
echo " Importing $pbfFile ..."
19
25
osmosis --read-pbf \
20
26
file=$pbfFile \
@@ -23,12 +29,13 @@ function importData () {
23
29
database=$POSTGRES_DB \
24
30
user=$POSTGRES_USER \
25
31
password=$POSTGRES_PASSWORD \
32
+ allowIncorrectSchemaVersion=yes \
26
33
validateSchemaVersion=no
27
34
else
28
35
# In case the file is .osm
29
36
# Extract the osm file
30
- bzip2 -d $file
31
- osmFile=${file % .* }
37
+ bzip2 -d $osmFile
38
+ osmFile=${osmFile % .* }
32
39
echo " Importing $osmFile ..."
33
40
osmosis --read-xml \
34
41
file=$osmFile \
@@ -39,6 +46,13 @@ function importData () {
39
46
password=$POSTGRES_PASSWORD \
40
47
validateSchemaVersion=no
41
48
fi
49
+ # Run required fixes in DB
50
+ psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c " select setval('current_nodes_id_seq', (select max(node_id) from nodes));"
51
+ psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c " select setval('current_ways_id_seq', (select max(way_id) from ways));"
52
+ psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c " select setval('current_relations_id_seq', (select max(relation_id) from relations));"
53
+ # psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c "select setval('users_id_seq', (select max(id) from users));"
54
+ # psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c "select setval('changesets_id_seq', (select max(id) from changesets));"
55
+
42
56
}
43
57
44
58
flag=true
0 commit comments