mirror of
https://github.com/fcwu/docker-ubuntu-vnc-desktop
synced 2025-12-06 08:22:31 +01:00
123 lines
No EOL
4.6 KiB
Bash
Executable file
123 lines
No EOL
4.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# Place this in /usr/bin/
|
|
|
|
SCRIPT="Generate Maps"
|
|
WORKING_DIRECTORY=/workspace/Graphhopper_Files
|
|
|
|
OK_RESPONSE () {
|
|
whiptail --title "$SCRIPT" --msgbox "$MESSAGE" 15 120
|
|
}
|
|
|
|
INFO_BOX () {
|
|
TERM=ansi whiptail --title "$SCRIPT" --infobox "$MESSAGE" 15 120
|
|
}
|
|
|
|
YES_NO_RESPONSE () {
|
|
whiptail --title "$SCRIPT" --yesno "$MESSAGE" 15 120
|
|
}
|
|
|
|
|
|
TEXT_INPUT () {
|
|
OUTPUT=$(whiptail --title "$SCRIPT" --inputbox "$MESSAGE" 8 80 "$PLACEHOLDER" 3>&1 1>&2 2>&3)
|
|
}
|
|
|
|
BUILD_MAP () {
|
|
{
|
|
# osmconvert extract
|
|
echo -e "XXX\n0\5\nCreating Directory... (${NAME}.osm) \nXXX"
|
|
mkdir -p ${WORKING_DIRECTORY}/${REGION}/${NAME}
|
|
echo "$(date) Starting Map Creation" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
sleep 1
|
|
echo -e "XXX\n20\nExtracting Coordinates... (${NAME}.osm) \nXXX"
|
|
if ! OUTPUT=$(osmconvert ${WORKING_DIRECTORY}/${REGION}/${MAP} -b=${COORDINATES} -o=${WORKING_DIRECTORY}/${REGION}/${NAME}/${NAME}.osm 2>&1); then
|
|
echo "An error occured during the first OSM convert (Part 1), Exiting."
|
|
echo "$OUTPUT"
|
|
echo "$(date) Coordinates failed to Extract" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
echo "$OUTPUT" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
exit 1
|
|
fi
|
|
echo "$OUTPUT" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
echo "$(date) Coordinates Extracted (${NAME}.osm)" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
|
|
# osmosis
|
|
echo -e "XXX\n65\nExporting Roads... (${NAME}roads.osm) \nXXX"
|
|
if ! OUTPUT=$(osmosis --read-xml ${WORKING_DIRECTORY}/${REGION}/${NAME}/${NAME}.osm --tf accept-ways highway=* --used-node --write-xml ${WORKING_DIRECTORY}/${REGION}/${NAME}/${NAME}roads.osm 2>&1); then
|
|
echo "An error occured in Osmosis (Part 2), Exiting."
|
|
echo "$OUTPUT"
|
|
echo "$(date) Exporting roads failed" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
echo "$OUTPUT" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
exit 1
|
|
fi
|
|
echo "$OUTPUT" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
echo "$(date) Roads Extracted (${NAME}roads.osm)" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
|
|
# osmconvert compress
|
|
echo -e "XXX\n90\nCompressing... (${NAME}.pbf)\nXXX"
|
|
if ! OUTPUT=$(osmconvert --out-pbf ${WORKING_DIRECTORY}/${REGION}/${NAME}/${NAME}roads.osm > ${WORKING_DIRECTORY}/${REGION}/${NAME}/${NAME}.pbf 2>&1); then
|
|
echo "An error occured during the second OSM convert (Part 3), Exiting."
|
|
echo "$OUTPUT"
|
|
echo "$(date) Compressing failed" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
echo "$OUTPUT" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
exit 1
|
|
fi
|
|
echo "$OUTPUT" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
echo "$(date) Compression complete (${NAME}.pbf)" >> ${WORKING_DIRECTORY}/${REGION}/${NAME}/log.txt
|
|
|
|
echo -e "XXX\n100\nProcess Completed Successfully! \nXXX"
|
|
sleep 1
|
|
} | whiptail --gauge "Please wait while the maps generate..." 6 80 0
|
|
}
|
|
|
|
# START OF SCRIPT
|
|
if ! OUTPUT=$(ls -1 /workspace/Graphhopper_Files 2>&1); then
|
|
echo "Your directory structure is not correct, exiting"
|
|
exit 1
|
|
fi
|
|
|
|
OUTPUT=/dev/null
|
|
MESSAGE="Enter the name for this map."; PLACEHOLDERR=""; TEXT_INPUT
|
|
if [[ ! -z $OUTPUT ]]; then
|
|
NAME=$( echo $OUTPUT | awk '{print tolower($0)}' | sed 's/ /_/g')
|
|
else
|
|
echo "The user did not enter a name. Exiting"
|
|
exit 1
|
|
fi
|
|
|
|
OUTPUT=/dev/null
|
|
MESSAGE="Enter the Region. (usa, europe)"; PLACEHOLDERR=""; TEXT_INPUT
|
|
if [[ ! -z $OUTPUT ]]; then
|
|
REGION=$( echo $OUTPUT | awk '{print tolower($0)}')
|
|
if [[ $REGION == "usa" ]]; then
|
|
MAP="us-latest.osm.pbf"
|
|
elif [[ $REGION == "usa" ]]; then
|
|
MAP="europe-latest.osm.pbf"
|
|
else
|
|
echo "The user did not enter a valid region. Exiting"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "The user did not enter a region. Exiting"
|
|
exit 1
|
|
fi
|
|
|
|
OUTPUT=/dev/null
|
|
MESSAGE="Enter the coordinates for this map."; PLACEHOLDER=""; TEXT_INPUT
|
|
if [[ ! -z $OUTPUT ]]; then
|
|
COORDINATES=$OUTPUT
|
|
else
|
|
echo "The user did not enter the coordinates. Exiting"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ $(echo $COORDINATES | sed 's/,/\n/g' | wc -l) != 4 ]]; then
|
|
echo "The user did not enter valid coordinates. Exiting"
|
|
exit 1
|
|
fi
|
|
|
|
MESSAGE="Please confirm the following details.\n\nNAME: $NAME\nREGION: $REGION\nCOORDINATES: $COORDINATES";
|
|
if ! YES_NO_RESPONSE; then
|
|
echo "User selected not to continue, exiting!"
|
|
exit 1
|
|
fi
|
|
|
|
BUILD_MAP |