2
0
Fork 0
containerfiles/osm-garmin/app/build-gmap.sh

189 lines
4.9 KiB
Bash
Raw Normal View History

2023-09-26 03:13:31 +02:00
#!/usr/bin/env bash
. /app/utils.sh
2023-09-26 05:01:15 +02:00
regions="$1"
2023-09-26 03:13:31 +02:00
style="$2"
cwd="$(pwd)"
function build_gmap() {
# TODO: Set name (currently is "OSM street map")
# Use --housenumbers?
# A way to pass extra options
# Change ID (currently is 63240000)
2023-09-26 03:13:31 +02:00
region="$1"
2023-10-01 03:10:17 +02:00
region_id="$2"
style="$3"
2023-09-26 03:13:31 +02:00
region_shortname="$(get_region_shortname "$region")"
2023-10-01 01:55:17 +02:00
generated_map_dir="$out_dir/$region_shortname/"
2023-10-01 03:44:53 +02:00
version_path="$generated_map_dir/version.txt"
2023-09-26 03:13:31 +02:00
bounds_dir_md5="$(get_md5_dir "$bounds_dir")"
map_md5="$(get_md5 "$maps_dir/$region_shortname.osm.pbf")"
2023-10-01 03:10:17 +02:00
style_md5="$(get_md5 "$styles_dir/$style.TYP")"
2023-09-26 03:13:31 +02:00
2023-10-01 03:44:53 +02:00
version_id=""
version_md5="$(echo "$bounds_dir_md5|$map_md5|$style_md5" | md5sum | cut -d' ' -f1)"
if [[ -f "$version_path" ]]; then
version_id="$(cat "$version_path" | cut -d'|' -f1)"
version_id="$((version_id+1))"
fi
version="$version_id|$version_md5"
2023-09-26 03:13:31 +02:00
build="true"
build_failed="false"
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"
2023-10-01 03:57:35 +02:00
family_name="osm-garmin"
2023-10-01 03:10:17 +02:00
[[ -n $OSMGARMIN_MAP_FAMILY_NAME ]] && family_name="$OSMGARMIN_MAP_FAMILY_NAME"
2023-10-01 04:23:19 +02:00
description="$(echo "${region##*/}" | sed -e "s/-/ /g" | sed -e "s/\b\(.\)/\u\1/g" | sed -e "s/ /-/g")"
2023-10-01 03:57:35 +02:00
product_id="$region_id"
product_version="$version_id"
2023-09-26 03:13:31 +02:00
exec_mkgmap \
--add-pois-to-areas \
2023-10-01 03:10:17 +02:00
--area-name="$region" \
2023-09-26 03:13:31 +02:00
--bounds="$bounds_dir" \
2023-10-01 03:50:49 +02:00
--description="$description" \
2023-10-01 03:10:17 +02:00
--family-name="$family_name" \
--product-id="$product_id" \
--product-version="$product_version" \
--series-name="$family_name" \
2023-10-01 04:23:19 +02:00
--gmapsupp \
--index \
--route \
2023-10-01 01:47:04 +02:00
$tiles_dir/$region_shortname/6324*.osm.pbf \
"$styles_dir/$style.TYP"
2023-09-26 03:13:31 +02:00
[[ $? != 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
rm -f "$styles_dir/x$style.TYP"
2023-09-26 03:13:31 +02:00
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"
2023-09-26 05:13:53 +02:00
#download_bounds "sea"
2023-09-26 03:13:31 +02:00
}
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"
2023-09-26 05:01:15 +02:00
regions_array="$(echo $regions | tr ";" "\n")"
2023-10-01 01:47:04 +02:00
is_updates="false"
[[ $OSMGARMIN_FORCE_BUILD == "true" ]] && is_updates="true"
2023-09-26 03:13:31 +02:00
2023-09-26 05:01:15 +02:00
for region in $regions_array; do
if [[ "$(check_osm_region_exists "$region")" == "true" ]]; then
if [[ "$(check_osm_update "$region")" == "true" ]]; then
echo "🌍 Updating OSM map: $region"
update_osm_map "$region"
2023-09-26 03:13:31 +02:00
2023-09-26 05:01:15 +02:00
echo "✂️ Building tiles: $region"
update_tiles "$region"
2023-10-01 01:47:04 +02:00
[[ $is_updates == "false" ]] && is_updates="true"
else
echo "⚠️ No updates to \"$region\""
2023-09-26 05:01:15 +02:00
fi
else
echo "⚠️ Region \"$region\" does not exist"
2023-09-26 03:13:31 +02:00
fi
2023-09-26 05:01:15 +02:00
done
2023-09-26 03:13:31 +02:00
2023-10-01 01:47:04 +02:00
if [[ $is_updates == "true" ]]; then
echo "📒 Updating bounds..."
update_bounds
2023-09-26 05:01:15 +02:00
2023-10-01 03:10:17 +02:00
region_id=1
2023-10-01 01:47:04 +02:00
for region in $regions_array; do
if [[ "$(check_osm_region_exists "$region")" == "true" ]]; then
echo "🔨 Building Garmin map: $region"
2023-10-01 03:10:17 +02:00
build_gmap "$region" "$region_id" "$style"
((region_id++))
2023-10-01 01:47:04 +02:00
fi
done
else
2023-10-01 02:45:43 +02:00
echo "⚠️ No new maps. Not building (set \$OSMGARMIN_FORCE_BUILD=true to override)"
2023-10-01 01:47:04 +02:00
fi
2023-09-26 03:13:31 +02:00
echo "🧹 Cleaning up..."
cleanup