2
0
Fork 0
containerfiles/osm-garmin/app/utils.sh

73 lines
1.5 KiB
Bash
Raw Normal View History

2023-09-26 03:13:31 +02:00
#!/usr/bin/env bash
2023-10-02 17:40:25 +02:00
osm_source_prefix="https://download.geofabrik.de/"
osm_source_suffix="-latest.osm.pbf"
osm_source_name="geofabrik"
2023-09-26 03:13:31 +02:00
bounds_dir="/data/build/bounds"
build_dir="/data/build/tmp"
2023-10-02 17:40:25 +02:00
maps_dir="/data/build/osm/$osm_source_name"
2023-09-26 03:13:31 +02:00
out_dir="/data/maps"
styles_dir="/data/styles"
tiles_dir="/data/build/tiles"
function die() {
echo "Error: $1"
exit 255
}
function check_osm_region_exists() {
region="$1"
exists="true"
curl -ILs --fail "$(get_pbf_url "$region")" &> /dev/null
2023-09-26 03:13:31 +02:00
[[ $? != 0 ]] && exists="false"
echo $exists
}
function check_osm_update() {
region="$1"
region_path="$maps_dir/$(get_region_shortname "$region").osm.pbf"
update="true"
md5="$(curl -Ls --fail "$(get_pbf_url "$region").md5" | cut -d' ' -f1)"
if [[ $? == 0 ]]; then
if [[ -f "$region_path" ]]; then
if [[ "$(get_md5 "$region_path")" == "$md5" ]]; then
update="false"
fi
fi
fi
echo $update
}
2023-10-02 17:40:25 +02:00
function exec_mkgmap() {
java -jar /opt/mkgmap/mkgmap.jar $@
}
function exec_splitter() {
java -jar /opt/splitter/splitter.jar $@
}
2023-09-26 03:13:31 +02:00
function get_md5() {
file="$1"
echo "$(md5sum "$file" | cut -d' ' -f1)"
}
function get_md5_dir() {
dir="$1"
echo "$(find "$dir" -type f -name "*.*" -exec md5sum {} + | awk '{print $1}' | sort | md5sum)"
}
function get_pbf_url() {
region="$1"
2023-10-02 17:40:25 +02:00
echo "${osm_source_prefix}${region}${osm_source_suffix}"
2023-09-26 03:13:31 +02:00
}
function get_region_shortname() {
region="$1"
2023-10-02 17:40:25 +02:00
echo "${region##*/}"
2023-09-26 03:13:31 +02:00
}