-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmapsme_gen.sh
executable file
·204 lines (184 loc) · 7.73 KB
/
mapsme_gen.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
# Usage info
show_help(){
cat << EOF
Usage: ${0##*/} [-hut] -c CONF_NUM COUNTRY REGION...
-h display this help and exit
-c CONF_NUM select config number.
-u upload geneated maps to the server.
-p SUFFIX upload path suffix.
-t enable working time calculation.
EOF
}
conf_num=0
upload=0
time_enable=0
while getopts "hutpc:" opt; do
case "$opt" in
h) show_help
exit 0
;;
c) conf_num=$OPTARG
echo "Used config $conf_num"
;;
u) upload=1
echo "Upload enabled"
;;
p) upload_path_suffix=daily
echo "Upload suffix $upload_path_suffix"
;;
t) time_enable=1
echo "Time compute enabled"
;;
esac
done
shift $((OPTIND-1))
upload_server_name_0="vpnmercury"
upload_server_name_1="db0.openstreetmap.ru"
upload_path_0="/var/www/webdav/mapsme/$upload_path_suffix"
upload_path_1="/usr/www/download/mapsme/$upload_path_suffix"
upload_server_path_0="$upload_server_name_0:$upload_path_0"
upload_server_path_1="$upload_server_name_1:$upload_path_1"
if [ $time_enable == "1" ]; then
time_log_file="/tmp/mapsme_time.log"
# Compute working time start
DT_START=$(date +%s)
fi
#Reset color
Color_Off='\e[0m' # Text Reset
#Colors
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
build_dir_name="/mnt/ramdisk/maps_build_$conf_num"
conf_file="$build_dir_name/map_generator.ini"
pl_url_s="https://download.geofabrik.de/"
main_region="russia"
sub_region="$1-latest.osm.pbf"
with_regions=0
# Select country
case "$1" in
"russia" ) main_region="russia"
with_regions=1 ;;
"russia_full" ) main_region=""
sub_region="russia-latest.osm.pbf" ;;
"belarus" ) main_region="europe" ;;
"ukraine" ) main_region="europe" ;;
"georgia" ) main_region="europe" ;;
"estonia" ) main_region="europe" ;;
"latvia" ) main_region="europe" ;;
"lithuania" ) main_region="europe" ;;
"finland" ) main_region="europe" ;;
"poland" ) main_region="europe" ;;
"czech-republic") main_region="europe" ;;
"serbia" ) main_region="europe" ;;
"slovakia" ) main_region="europe" ;;
"slovenia" ) main_region="europe" ;;
"hungary" ) main_region="europe" ;;
"romania" ) main_region="europe" ;;
"bosnia-herzegovina") main_region="europe" ;;
"bulgaria" ) main_region="europe" ;;
"moldova" ) main_region="europe" ;;
"austria" ) main_region="europe" ;;
"greece" ) main_region="europe" ;;
"turkey" ) main_region="europe" ;;
"armenia" ) main_region="asia" ;;
"azerbaijan" ) main_region="asia" ;;
"kazakhstan" ) main_region="asia" ;;
"mongolia" ) main_region="asia" ;;
"north-korea" ) main_region="asia" ;;
"uzbekistan" ) main_region="asia" ;;
"turkmenistan" ) main_region="asia" ;;
"kyrgyzstan" ) main_region="asia" ;;
"tajikistan" ) main_region="asia" ;;
"tunisia" ) main_region="africa" ;;
* ) echo "Need country"
exit 1 ;;
esac
shift
# select region
if [ $with_regions -eq 1 ]; then
case "$1" in
"Russia_Moscow" ) sub_region="central-fed-district-latest.osm.pbf" ;;
"Russia_Bashkortostan" ) sub_region="volga-fed-district-latest.osm.pbf" ;;
"Russia_Krasnodar Krai" ) sub_region="south-fed-district-latest.osm.pbf" ;;
"Crimea" ) sub_region="crimean-fed-district-latest.osm.pbf" ;;
"Russia_Arkhangelsk Oblast_Central" ) sub_region="northwestern-fed-district-latest.osm.pbf" ;;
"Russia_Kaliningrad Oblast" ) sub_region="kaliningrad-latest.osm.pbf" ;;
"Russia_Republic of Dagestan" ) sub_region="north-caucasus-fed-district-latest.osm.pbf" ;;
"Russia_Kurgan Oblast" ) sub_region="ural-fed-district-latest.osm.pbf" ;;
"Russia_Altai Krai" ) sub_region="siberian-fed-district-latest.osm.pbf" ;;
"Russia_Amur Oblast" ) sub_region="far-eastern-fed-district-latest.osm.pbf" ;;
# "Poland_Greater Poland Voivodeship" ) sub_region="https://download.geofabrik.de/europe/poland-latest.osm.pbf" ;;
# "Poland_Kuyavian-Pomeranian Voivodeship")sub_region="kujawsko-pomorskie-latest.osm.pbf" ;;
# "Poland_Lesser Poland Voivodeship" ) sub_region="malopolskie-latest.osm.pbf" ;;
# "Poland_Lodz Voivodeship" ) sub_region="lodzkie-latest.osm.pbf" ;;
# "Poland_Lower Silesian Voivodeship" ) sub_region="dolnoslaskie-latest.osm.pbf" ;;
# "Poland_Lublin Voivodeship" ) sub_region="lubelskie-latest.osm.pbf" ;;
# "Poland_Lubusz Voivodeship" ) sub_region="lubuskie-latest.osm.pbf" ;;
# "Poland_Masovian Voivodeship" ) sub_region="mazowieckie-latest.osm.pbf" ;;
# "Poland_Opole Voivodeship" ) sub_region="opolskie-latest.osm.pbf" ;;
# "Poland_Podlaskie Voivodeship" ) sub_region="podlaskie-latest.osm.pbf" ;;
# "Poland_Pomeranian Voivodeship" ) sub_region="pomorskie-latest.osm.pbf" ;;
# "Poland_Silesian Voivodeship" ) sub_region="slaskie-latest.osm.pbf" ;;
# "Poland_Subcarpathian Voivodeship" ) sub_region="podkarpackie-latest.osm.pbf" ;;
# "Poland_Swietokrzyskie Voivodeshi" ) sub_region="swietokrzyskie-latest.osm.pbf" ;;
# "Poland_Warmian-Masurian Voivodeship") sub_region="warminsko-mazurskie-latest.osm.pbf" ;;
# "Poland_West Pomeranian Voivodeship") sub_region="zachodniopomorskie-latest.osm.pbf" ;;
* ) echo "Need region"
exit 2 ;;
esac
fi
declare -a COUNT
max_count=$#
for i in $(seq 1 $max_count);do
COUNT[$i]=$1
shift
done
COUNTRIES=${COUNT[1]}
for i in $(seq 2 $max_count);do
COUNTRIES=$(echo $COUNTRIES,${COUNT[$i]})
done
# Create build directory on ramdisk
if [ ! -e $build_dir_name ]; then
mkdir $build_dir_name
else
rm -rf $build_dir_name/*
fi
# Change config to build requested maps
pushd ~/mapsme/omim/tools/python
cp maps_generator/var/etc/map_generator.ini $conf_file
sed -e "s|.*PLANET_URL.*|PLANET_URL: ${pl_url_s}${main_region}/${sub_region}|" \
-e "s|.*PLANET_MD5_URL.*|PLANET_MD5_URL: ${pl_url_s}${main_region}/${sub_region}.md5|" \
-e "s|/mnt/ramdisk/maps_build.*|$build_dir_name|" \
-e "s|OSM_TOOLS_PATH: ~/osmctools|OSM_TOOLS_PATH: $build_dir_name/osmctools|" \
-i $conf_file
# Run maps build
python3 -m maps_generator --config $conf_file --countries="$COUNTRIES" --skip="Coastline"
STATUS=$?
# python3 -m maps_generator --config $conf_file --countries="$COUNTRIES" --skip="coastline,routing_transit"
popd
# Upload maps to server
if [ $upload -eq 1 ]; then
if [ $STATUS -eq 0 ]; then
for i in $(seq 1 $max_count);do
echo "$i $max_count"
find $build_dir_name -name "${COUNT[$i]}.mwm" -exec scp {} $upload_server_path_0 \;
ssh $upload_server_name_0 "scp \"$upload_path_0/${COUNT[$i]}.mwm\" $upload_server_path_1" &
done
rm -rf $build_dir_name
else
for i in $(seq 1 $max_count);do
find $build_dir_name -name "${COUNT[$i]}.mwm" -delete
done
echo -e "${Red}Build failed!${Color_Off}"
exit 3
fi
fi
# rm -rf $build_dir_name
if [ $time_enable == "1" ]; then
# Compute working time end
DT_END=$(date +%s)
work_m=$(echo "($DT_END - $DT_START)/60" | bc -l)
echo ${main_region}-${sub_region} $work_m >> $time_log_file
fi