-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_run.sh
executable file
·167 lines (158 loc) · 5.83 KB
/
docker_run.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
re_integer='^[0-9]+$'
while getopts ":n:d:b:t:o:sxgv:iml:ucz:e" opt; do
case $opt in
n) PROJECT_NAME_EXT="$OPTARG"
;;
d) qgis_projects_dir="$OPTARG"
;;
b) BBOX_STR="$OPTARG"
;;
t) terrain_src_dir="$OPTARG"
;;
s) DOWNLOAD_TERRAIN_DATA=true
;;
o) if [[ "$OPTARG" == "external" ]] || [[ "$OPTARG" == "ext" ]] ; then
OVERPASS_INSTANCE=external
elif [[ "$OPTARG" == "docker" ]] ; then
OVERPASS_INSTANCE=docker
else
echo -e "\033[91mInvalid -o value. Use [ external (ext) | docker ]\033[0m"
fi
;;
x) RUN_CHAIN=true
;;
g) generate_terrain=true
;;
v) overpass_endpoint_external="$OPTARG"
;;
i) generate_terrain_isolines=true
;;
m) smooth_isolines=true
;;
l) if [[ "$OPTARG" =~ $re_integer ]] ; then
isolines_step="$OPTARG"
else
echo -e "\033[91mInvalid -l value. Isolines step is not an integer.\033[0m"
exit 1
fi
;;
u) overpass_endpoint_docker_use_bbox=true
;;
c) overpass_endpoint_docker_clear_db=true
;;
e) generate_terrain_hillshade_slope=true
;;
z) if [[ "$OPTARG" == "cubicspline" ]] ; then
terrain_resample_method=cubicspline
elif [[ "$OPTARG" == "lanczos" ]] ; then
terrain_resample_method=lanczos
else
echo -e "\033[91mInvalid -z value. Use [ cubicspline | lanczos ]\033[0m"
fi
;;
\?) echo -e "\033[91mInvalid option -$OPTARG\033[0m" >&2
;;
esac
done
usage_str="Usage: ./docker_run.sh -n project_name -d /path/to/projects/dir [ -b lon_min,lat_min,lon_max,lat_max ] [ -o [external | docker] ] [ -s ] [ -t /path/to/terrain/dir ] { -o : use external / docker Overpass server, -s : automatically download SRTM30m terrain data, -x : execute sequential data preparation steps }"
lang_local_str=$(locale | grep LANG=)
lang=${lang_local_str#LANG=}
if [[ ! -z $lang ]] ; then
lang_str="-e LANG=$lang"
fi
if [[ -f "docker_run.ini" ]] ; then
. docker_run.ini
fi
if [[ -z $PROJECT_NAME_EXT ]] ; then
echo -e "\033[93mProject name is not specified. Use 'automap' by default.\033[0m";
PROJECT_NAME_EXT=automap
fi
if [[ -z $qgis_projects_dir ]] ; then
echo -e "\033[91mQGIS projects dir is not specified. $usage_str\033[0m" && exit 1;
fi
if [[ ! -z $terrain_src_dir ]] && [[ ! -d $terrain_src_dir ]] ; then
echo -e "\033[91mterrain_src_dir doesn't exist. $usage_str\033[0m" && exit 1;
fi
function echo_bbox_invalid {
echo -e "\033[91mInvalid bbox format. Use OpenStreetMap link or left,bottom,right,top (lon_min,lat_min,lon_max,lat_max).\033[0m" && exit 1;
}
function overpass_endpoint_invalid {
echo -e "\033[91mInvalid Overpass endpoint format\033[0m" && exit 1;
}
if [[ ! -z $BBOX_STR ]] ; then
if [[ $BBOX_STR == *","* ]] && [[ $BBOX_STR != *"openstreetmap"* ]] ; then
IFS=',' read -r -a array_bbox <<< "$BBOX_STR"
lon_min=${array_bbox[0]}
lat_min=${array_bbox[1]}
lon_max=${array_bbox[2]}
lat_max=${array_bbox[3]}
if [[ ${#array_bbox[@]} -ne 4 ]] || [[ -z $lon_min ]] || [[ -z $lat_min ]] || [[ -z $lon_max ]] || [[ -z $lat_max ]] ; then echo_bbox_invalid; fi
if (( $(echo "$lon_min > $lon_max" | bc -l) )) || (( $(echo "$lat_min > $lat_max" | bc -l) )) || \
(( $(echo "$lat_max > 90" | bc -l) )) || (( $(echo "$lat_min < -90" | bc -l) )) || \
(( $(echo "$lon_min < -179.99" | bc -l) )) || (( $(echo "$lon_max > 179.99" | bc -l) )) ; then
echo_bbox_invalid
fi
elif [[ $BBOX_STR == *"openstreetmap"* ]] ; then
BBOX_STR=\"$BBOX_STR\"
else
echo_bbox_invalid
fi
fi
if [[ $overpass_endpoint_external == *"interpreter"* ]] ; then
overpass_endpoint_external=\"$overpass_endpoint_external\"
elif [[ ! -z $overpass_endpoint_external ]] ; then
overpass_endpoint_invalid
fi
if [[ -f "config_debug.ini" ]] ; then
docker_image="qgis-xtopo"
else
docker_image="xmd5a2/qgis-xtopo:latest"
fi
if [[ ! -z $qgis_projects_dir ]] && [[ ! -d $qgis_projects_dir ]] ; then
mkdir -p $qgis_projects_dir
fi
if [[ -d $terrain_src_dir ]] ; then
terrain_mount_str="--mount type=bind,source=$terrain_src_dir,target=/mnt/terrain"
fi
if [[ ! -z $qgis_projects_dir ]] ; then
echo -e "\e[100mqgis_projects_dir=$qgis_projects_dir\e[49m"
echo -e "\e[100mproject_name=$PROJECT_NAME_EXT\e[49m"
echo -e "\e[100mbbox=$BBOX_STR\e[49m"
echo -e "\e[100mterrain_src_dir=$terrain_src_dir\e[49m"
echo -e "\e[100moverpass_db_dir=$qgis_projects_dir/overpass_db\e[49m"
echo -e "\e[100mqgisxtopo_config_dir=$qgis_projects_dir/qgisxtopo-config\e[49m"
if [[ ! -z $OVERPASS_INSTANCE ]] ; then
echo -e "\e[100moverpass_instance=$OVERPASS_INSTANCE\e[49m"
fi
if [[ ! -z $DOWNLOAD_TERRAIN_DATA ]] ; then
echo -e "\e[100mdownload_terrain_data=true\e[49m"
fi
fi
if [[ $(docker container ls | grep qgis-xtopo) ]] ; then
docker stop qgis-xtopo
fi
if [[ -d "$qgis_projects_dir" ]] ; then
docker run -dti --rm -e PROJECT_NAME_EXT=$PROJECT_NAME_EXT -e BBOX_STR=$BBOX_STR -e OVERPASS_INSTANCE=$OVERPASS_INSTANCE \
-e GENERATE_TERRAIN=$generate_terrain -e DOWNLOAD_TERRAIN_DATA=$DOWNLOAD_TERRAIN_DATA -e RUN_CHAIN=$RUN_CHAIN \
-e GENERATE_TERRAIN_ISOLINES=$generate_terrain_isolines -e SMOOTH_ISOLINES=$smooth_isolines \
-e OVERPASS_ENDPOINT_DOCKER_USE_BBOX=$overpass_endpoint_docker_use_bbox \
-e OVERPASS_ENDPOINT_DOCKER_CLEAR_DB=$overpass_endpoint_docker_clear_db \
-e ISOLINES_STEP=$isolines_step \
-e GENERATE_TERRAIN_HILLSHADE_SLOPE=$generate_terrain_hillshade_slope \
-e TERRAIN_RESAMPLE_METHOD=$terrain_resample_method \
-e OVERPASS_ENDPOINT_EXTERNAL=$overpass_endpoint_external \
-v /tmp/.X11-unix:/tmp/.X11-unix $lang_str -e DISPLAY \
--name qgis-xtopo \
--mount type=bind,source=$qgis_projects_dir,target=/mnt/qgis_projects \
$terrain_mount_str \
$docker_image
fi
if [[ $(docker container ls | grep qgis-xtopo) ]] ; then
docker exec -it --user user qgis-xtopo /app/init_docker.sh
fi
if [[ $RUN_CHAIN == true ]] ; then
if [[ ! -f $config_dir/err_prepare_data.flag ]] && [[ ! -f $config_dir/err_populate_db.flag ]] ; then
. docker_exec_qgis.sh
fi
fi