155 lines
3.6 KiB
Bash
Executable File
155 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
. /app/utils.sh
|
|
|
|
regions="$1"
|
|
style="$2"
|
|
|
|
cwd="$(pwd)"
|
|
|
|
function build_gmap() {
|
|
region="$1"
|
|
style="$2"
|
|
|
|
region_shortname="$(get_region_shortname "$region")"
|
|
|
|
bounds_dir_md5="$(get_md5_dir "$bounds_dir")"
|
|
map_md5="$(get_md5 "$maps_dir/$region_shortname.osm.pbf")"
|
|
version="$(echo "$bounds_dir_md5|$map_md5" | md5sum | cut -d' ' -f1)"
|
|
|
|
generated_map_dir="$out_dir/$region_shortname/"
|
|
version_path="$generated_map_dir/version.txt"
|
|
|
|
build="true"
|
|
build_failed="false"
|
|
|
|
if [[ -n "$style" ]]; then
|
|
style="$styles_dir/$style.TYP"
|
|
fi
|
|
|
|
mkdir -p "$generated_map_dir"
|
|
|
|
if [[ -f "$version_path" ]]; then
|
|
if [[ $(cat "$version_path") == "$version" ]]; then
|
|
build="false"
|
|
fi
|
|
fi
|
|
|
|
if [[ $build == "true" ]]; then
|
|
cd "$build_dir"
|
|
|
|
exec_mkgmap \
|
|
--add-pois-to-areas \
|
|
--bounds="$bounds_dir" \
|
|
--gmapsupp \
|
|
--index \
|
|
--route \
|
|
$tiles_dir/$region_shortname/6324*.osm.pbf $style
|
|
|
|
[[ $? != 0 ]] && build_failed="true"
|
|
cd "$cwd"
|
|
|
|
if [[ $build_failed == "false" ]]; then
|
|
rm -f $generated_map_dir/*
|
|
|
|
mv "$build_dir/gmapsupp.img" "$generated_map_dir/"
|
|
mv "$build_dir/osmmap.img" "$generated_map_dir/"
|
|
mv "$build_dir/osmmap.tdb" "$generated_map_dir/"
|
|
echo "$version" > "$version_path"
|
|
|
|
rm -f $build_dir/*
|
|
else
|
|
rm -f $build_dir/*
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function cleanup() {
|
|
rm -f "$build_dir/*"
|
|
}
|
|
|
|
function exec_mkgmap() {
|
|
java -jar /opt/mkgmap/mkgmap.jar $@
|
|
}
|
|
|
|
function exec_splitter() {
|
|
java -jar /opt/splitter/splitter.jar $@
|
|
}
|
|
|
|
function update_bounds() {
|
|
function download_bounds() {
|
|
type="$1"
|
|
bounds_url_prefix="https://www.thkukuk.de/osm/data"
|
|
|
|
curl -L --fail "$bounds_url_prefix/$type-latest.zip" -o "$bounds_dir/$type.zip"
|
|
unzip -o "$bounds_dir/$type.zip" -d "$bounds_dir"
|
|
rm -f "$bounds_dir/$type.zip"
|
|
}
|
|
|
|
download_bounds "bounds"
|
|
download_bounds "sea"
|
|
}
|
|
|
|
function update_osm_map() {
|
|
region="$1"
|
|
region_filename="$(get_region_shortname "$region").osm.pbf"
|
|
region_path="$maps_dir/$region_filename"
|
|
|
|
curl -L "$(get_pbf_url "$region")" -o "$region_path"
|
|
}
|
|
|
|
function update_tiles() {
|
|
region="$1"
|
|
region_tiles_dir="$tiles_dir/$(get_region_shortname "$region")"
|
|
|
|
mkdir -p "$region_tiles_dir"
|
|
rm -rf "$region_tiles_dir/*"
|
|
cd "$region_tiles_dir" # HACK: --output-dir doesn't work
|
|
|
|
exec_splitter "$maps_dir/$(get_region_shortname "$region").osm.pbf"
|
|
|
|
cd "$cwd"
|
|
}
|
|
|
|
mkdir -p "$bounds_dir"
|
|
mkdir -p "$build_dir"
|
|
mkdir -p "$maps_dir"
|
|
mkdir -p "$out_dir"
|
|
mkdir -p "$tiles_dir"
|
|
|
|
if [[ -z $region ]]; then
|
|
die "No region specified"
|
|
fi
|
|
|
|
regions_array="$(echo $regions | tr ";" "\n")"
|
|
|
|
for region in $regions_array; do
|
|
if [[ "$(check_osm_region_exists "$region")" == "true" ]]; then
|
|
echo "👀 Checking OSM updates: $region"
|
|
|
|
if [[ "$(check_osm_update "$region")" == "true" ]]; then
|
|
echo "🌍 Updating OSM map: $region"
|
|
update_osm_map "$region"
|
|
|
|
echo "✂️ Building tiles: $region"
|
|
update_tiles "$region"
|
|
fi
|
|
else
|
|
echo "⚠️ Region \"$region\" does not exist"
|
|
fi
|
|
done
|
|
|
|
echo "📒 Updating bounds..."
|
|
update_bounds
|
|
|
|
for region in $regions_array; do
|
|
if [[ "$(check_osm_region_exists "$region")" == "true" ]]; then
|
|
echo "🔨 Building Garmin map: $region"
|
|
build_gmap "$region" "$style"
|
|
else
|
|
echo "⚠️ Region \"$region\" does not exist"
|
|
fi
|
|
done
|
|
|
|
echo "🧹 Cleaning up..."
|
|
cleanup |