From 1a836e318c1113f561cda6336dcb705013318405 Mon Sep 17 00:00:00 2001 From: Gaston Gonzalez Date: Mon, 4 Nov 2024 04:12:51 -0700 Subject: [PATCH] Maps - Added a script to download and generate map data based on user selection --- scripts/download-osm-maps.sh | 65 ++++++++++++++++++++++++++++++++++++ scripts/install.sh | 5 ++- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100755 scripts/download-osm-maps.sh diff --git a/scripts/download-osm-maps.sh b/scripts/download-osm-maps.sh new file mode 100755 index 0000000..0d96f32 --- /dev/null +++ b/scripts/download-osm-maps.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# Author : Gaston Gonzalez +# Date : 4 November 2024 +# Purpose : Downloads OSM .pbf file selected by user + +HTML=page.html +URL=http://download.geofabrik.de/north-america/us.html + +# Location to store OSM .bpf files +PBF_MAP_DIR=/etc/skel/my-maps + +[ ! -e ${PBF_MAP_DIR} ] && mkdir -v ${PBF_MAP_DIR} + +if [ ! -e ${HTML} ]; then + et-log "Downloading list of maps files for the US..." + curl -s -L -f -o ${HTML} ${URL} + + if [ $? -ne 0 ]; then + et-log "Can't download list map data from ${URL}. Exiting..." + exit 1 + fi +fi + +et-log "Extracting state-level .pbf file list..." + +options=() +while IFS= read -r state_html; do + state_file_suffix=$(echo $state_html | sed -n 's/.*href="\([^"]*\)".*/\1/p') + pbf_file=$(echo $state_file_suffix | sed 's|bz2|pbf|') + state_url="http://download.geofabrik.de/north-america/${pbf_file}" + + # Extract a display friendly name for the state + state_name=$(echo $state_file_suffix | sed 's|us/||' | sed 's|-latest.osm.bz2||') + + options+=("$state_name" "$state_url") +done < <(grep "[.]pbf" page.html | grep 'href="us/' | sort) + +SELECTED_STATE=$(dialog --clear --menu "Select a map file:" 20 80 10 "${options[@]}" 3>&1 1>&2 2>&3) +exit_status=$? + +tput sgr 0 && clear + +if [ $exit_status -eq 0 ]; then + download_file="${SELECTED_STATE}-latest.osm.pbf" + download_url="http://download.geofabrik.de/north-america/us/${download_file}" + + if [ -e ${download_file} ]; then + et-log "${download_file} already exists. Skipping download." + else + et-log "Downloading ${download_url}." + curl -L -f -O ${download_url} + fi + + + if [ -e ${download_file} ]; then + navit_osm_bin_file=$(echo ${download_file} | sed 's|pbf|bin|') + navit_osm_bin_file_path="/etc/skel/.navit/maps/${navit_osm_bin_file}" + et-log "Generating OSM map for Navit: ${navit_osm_bin_file_path}" + maptool --protobuf -i ${download_file} ${navit_osm_bin_file_path} + + et-log "Moving OSM .pbf to ${PBF_MAP_DIR}" + mv -v ${download_file} ${PBF_MAP_DIR} + fi +fi + diff --git a/scripts/install.sh b/scripts/install.sh index 7fda58c..5ed4a70 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -2,7 +2,7 @@ # # Author : Gaston Gonzalez # Date : 16 March 2024 -# Updated : 3 November 2024 +# Updated : 4 November 2024 # Purpose : Main installer for EmComm Tools OS Community . ./env.sh @@ -40,3 +40,6 @@ exitIfNotRoot ./install-yaac.sh ./install-audio-tools.sh + +# Add user-specific data +./download-osm-maps.sh