-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathentrypoint.sh
More file actions
78 lines (73 loc) · 2.03 KB
/
Copy pathentrypoint.sh
File metadata and controls
78 lines (73 loc) · 2.03 KB
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
71
72
73
74
75
76
77
78
#!/bin/sh
set -e
DATA_DIR="${DATA_DIR:-/data}"
download_pbf() {
mkdir -p "$DATA_DIR/pbf"
for url in $PBF_URLS; do
filename=$(basename "$url")
if [ ! -f "$DATA_DIR/pbf/$filename" ]; then
echo "Downloading $url..."
curl -fSL -o "$DATA_DIR/pbf/$filename" "$url"
else
echo "Already downloaded: $filename"
fi
done
}
build_index() {
files=""
for f in "$DATA_DIR"/pbf/*.osm.pbf; do
[ -f "$f" ] && files="$files $f"
done
if [ -z "$files" ]; then
echo "Error: no PBF files found in $DATA_DIR/pbf/"
exit 1
fi
if [ -f "$DATA_DIR/index/geo_cells.bin" ]; then
echo "Index already exists, skipping build"
return
fi
mkdir -p "$DATA_DIR/index"
level_args=""
[ -n "$STREET_LEVEL" ] && level_args="$level_args --street-level $STREET_LEVEL"
[ -n "$ADMIN_LEVEL" ] && level_args="$level_args --admin-level $ADMIN_LEVEL"
echo "Building index..."
build-index "$DATA_DIR/index" $files $level_args
echo "Index built."
}
serve() {
if [ ! -f "$DATA_DIR/geocoder.json" ] && [ -f "$DATA_DIR/index/geocoder.json" ]; then
echo "Migrating geocoder.json out of index folder..."
mv "$DATA_DIR/index/geocoder.json" "$DATA_DIR/geocoder.json"
fi
args="$DATA_DIR"
if [ -n "$DOMAIN" ]; then
args="$args --domain $DOMAIN"
if [ -n "$CACHE_DIR" ]; then
args="$args --cache $CACHE_DIR"
fi
else
args="$args ${BIND_ADDR:-0.0.0.0:3000}"
fi
[ -n "$STREET_LEVEL" ] && args="$args --street-level $STREET_LEVEL"
[ -n "$ADMIN_LEVEL" ] && args="$args --admin-level $ADMIN_LEVEL"
[ -n "$SEARCH_DISTANCE" ] && args="$args --search-distance $SEARCH_DISTANCE"
echo "Starting server..."
exec query-server $args
}
case "${1:-auto}" in
build)
download_pbf
build_index
;;
serve)
serve
;;
auto)
download_pbf
build_index
serve
;;
*)
exec "$@"
;;
esac