forked from simonepri/docker-osrm-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
osrm.sh
executable file
·70 lines (60 loc) · 2.7 KB
/
osrm.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
62
63
64
65
66
67
68
69
70
#!/bin/sh
OSRM_DATA_PATH="/data"
_sig() {
kill -TERM $child 2>/dev/null
}
# trap _sig SIGKILL SIGTERM SIGHUP SIGINT EXIT
# Check for existing mldgr or hsgr files and skip extraction if present
if [ ! -f $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm.mldgr ] && [ ! -f $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm.hsgr ]; then
if [ ! -f $OSRM_DATA_PATH/$OSRM_MAP_NAME.osm.pbf ]; then
echo "Downloading $OSRM_MAP_NAME from $OSRM_MAP_URL"
curl -L $OSRM_MAP_URL --create-dirs -o $OSRM_DATA_PATH/$OSRM_MAP_NAME.osm.pbf
reteval=$?
if [ ${reteval} -ne 0 ]; then
echo "$OSRM_MAP_NAME download to $OSRM_DATA_PATH/$OSRM_MAP_NAME.osm.pbf failed"
exit 1;
fi
FILESIZE=$(stat -c%s "$OSRM_DATA_PATH/$OSRM_MAP_NAME.osm.pbf")
echo "$OSRM_MAP_NAME downloaded to $OSRM_DATA_PATH/$OSRM_MAP_NAME.osm.pbf ($FILESIZE bytes)"
fi
echo "Extracting the Road Network from $OSRM_DATA_PATH/$OSRM_MAP_NAME.osm.pbf using $OSRM_EXT_PROFILE profile"
osrm-extract -p /opt/$OSRM_EXT_PROFILE.lua $OSRM_DATA_PATH/$OSRM_MAP_NAME.osm.pbf
reteval=$?
if [ ${reteval} -ne 0 ]; then
echo "$OSRM_MAP_NAME extraction to $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm failed"
exit 1;
fi
FILESIZE=$(stat -c%s "$OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm")
echo "$OSRM_MAP_NAME extracted to $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm ($FILESIZE bytes)"
echo "Deleting $OSRM_DATA_PATH/$OSRM_MAP_NAME.osm.pbf"
rm $OSRM_DATA_PATH/$OSRM_MAP_NAME.osm.pbf
if [ "$OSRM_PIPELINE" = "CH" ]; then
echo "Contracting $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm"
osrm-contract $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm
FILESIZE=$(stat -c%s "$OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm.hsgr")
echo "$OSRM_MAP_NAME hierarchy precomputed using $OSRM_PIPELINE to $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm.hsgr ($FILESIZE bytes)"
else
OSRM_PIPELINE="MLD"
echo "Creating Hierarchy from $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm"
osrm-partition $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm
if [ ${reteval} -ne 0 ]; then
echo "$OSRM_MAP_NAME hierarchy precomputation to $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm failed"
exit 1;
fi
osrm-customize $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm
FILESIZE=$(stat -c%s "$OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm.mldgr")
echo "$OSRM_MAP_NAME precomputed using $OSRM_PIPELINE to $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm.mldgr ($FILESIZE bytes)"
fi
echo "$OSRM_MAP_NAME.osm.pbf pre-processing ended"
fi
echo "Pipeline = $OSRM_PIPELINE"
if [ "$OSRM_PIPELINE" = "CH" ]; then
OSRM_API_PARAMS="$OSRM_API_PARAMS --algorithm CH"
else
OSRM_API_PARAMS="$OSRM_API_PARAMS --algorithm MLD"
fi
echo "API Params = $OSRM_API_PARAMS"
echo "Starting routing engine HTTP server"
osrm-routed $OSRM_DATA_PATH/$OSRM_MAP_NAME.osrm $OSRM_API_PARAMS &
child=$!
wait "$child"