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

61 lines
1.3 KiB
Bash

#!/usr/bin/env bash
bounds_dir="/data/build/bounds"
build_dir="/data/build/tmp"
maps_dir="/data/build/osm"
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
[[ $? != 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
}
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"
echo "https://download.geofabrik.de/$region-latest.osm.pbf"
}
function get_region_shortname() {
region="$1"
echo "$(echo "$region" | sed "s/\//./g")"
}