-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_osm_dump.sh
executable file
·62 lines (48 loc) · 1.69 KB
/
update_osm_dump.sh
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /bin/sh
# Обновляет гислабовский дамп OSM
# Запуск: update_osm_dump.sh <dump_fullpath> [<bound poly>]
set -e
BASEURL=http://be.gis-lab.info/data/osm_dump/dump/latest
TEMPDIR=/data/garmin/tmp
if [ $# -lt 2 ]
then
echo "Run: update_osm_dump.sh <dump_name> <dump_fullpath> [<bound poly>]"
exit 1
fi
DUMPPATH=$2
DUMPNAME=$1
DUMP=$DUMPPATH/${DUMPNAME}.osm.o5m
DUMPURL=$BASEURL/${DUMPNAME}.osm.pbf
DUMPMETA=$DUMPPATH/${DUMPNAME}.osm.pbf.meta
DUMPMETAURL=$BASEURL/${DUMPNAME}.osm.pbf.meta
POLY=$3
OPTIONS_OSMCV="-v -t=${TEMPDIR}/osmconvert_temp"
OPTIONS_OSMUP="-v -t=${TEMPDIR}/osmupdate_temp --out-o5m"
if [ -n "$POLY" ]
then
OPTIONS_OSMUP="$OPTIONS_OSMUP -B=$POLY"
fi
cd $TEMPDIR
# проверяем версию дампа на гислабе
# если дамп нарезан из свежей планеты, обновляемся
echo "checking planet version"
wget $DUMPMETAURL -O ${DUMPMETA}.new
planet_date_new=$(awk 'BEGIN{FS=/[ =]/;}$1 == "planet_version" {print $3;}' ${DUMPMETA}.new)
if [ -f "$DUMPMETA" ]
then
planet_date=$(awk 'BEGIN{FS=/[ =]/;}$1 == "planet_version" {print $3;}' ${DUMPMETA})
fi
if [ "$planet_date" != "$planet_date_new" ]
then
echo "remote dump was updated from planet at $planet_date_new, downloading"
wget $DUMPURL -O ${DUMP}.new.pbf
echo "converting dump to o5m"
osmconvert $OPTIONS_OSMCV ${DUMP}.new.pbf -o=${DUMP}.new.o5m
mv -v ${DUMP}.new.o5m ${DUMP}
rm ${DUMP}.new.pbf
fi
mv -v ${DUMPMETA}.new ${DUMPMETA}
# обновляем локальный дамп с сервера планеты
echo "updating dump from motherplanet"
osmupdate $OPTIONS_OSMUP $DUMP ${DUMP}.new
mv -v ${DUMP}.new ${DUMP}