Maps - Added a script to download and generate map data based on user selection

This commit is contained in:
Gaston Gonzalez
2024-11-04 04:12:51 -07:00
parent 04ff63ba88
commit 1a836e318c
2 changed files with 69 additions and 1 deletions
+65
View File
@@ -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
+4 -1
View File
@@ -2,7 +2,7 @@
# #
# Author : Gaston Gonzalez # Author : Gaston Gonzalez
# Date : 16 March 2024 # Date : 16 March 2024
# Updated : 3 November 2024 # Updated : 4 November 2024
# Purpose : Main installer for EmComm Tools OS Community # Purpose : Main installer for EmComm Tools OS Community
. ./env.sh . ./env.sh
@@ -40,3 +40,6 @@ exitIfNotRoot
./install-yaac.sh ./install-yaac.sh
./install-audio-tools.sh ./install-audio-tools.sh
# Add user-specific data
./download-osm-maps.sh