91 lines
2.6 KiB
Bash
Executable File
91 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
if ! command -v jq &> /dev/null; then
|
|
echo "jq is not installed. Installing..."
|
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
sudo apt update && sudo apt install -y jq || sudo yum install -y jq
|
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
|
brew install jq
|
|
else
|
|
echo "Unsupported OS. Please install jq manually."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
CURRENT_PATH=$(pwd)
|
|
DATA_PATH=${CURRENT_PATH}/data
|
|
echo "Current DATA_PATH: ($DATA_PATH)"
|
|
read -p "Enter a new data path or press Enter to use the default: " USER_PATH
|
|
DATA_PATH=${USER_PATH:-$DATA_PATH}
|
|
echo "Using path: ($DATA_PATH)"
|
|
sed -i "s|^DATA_DIR=.*|DATA_DIR=${DATA_PATH}|" .env
|
|
|
|
|
|
DEFAULT_PORT=$(cat .env | awk -F'=' '/^PORT=/ {print $2}')
|
|
read -p "Enter a new port or press Enter to use the current: ${DEFAULT_PORT} " USER_PORT
|
|
DEFAULT_PORT=${USER_PORT:-$DEFAULT_PORT}
|
|
echo "Using Port: ($DEFAULT_PORT)"
|
|
sed -i "s|^PORT=.*|PORT=${DEFAULT_PORT}|" .env
|
|
|
|
FILES=($(find . -type f -name "*.mbtiles"))
|
|
if [ ${#FILES[@]} -eq 0 ]; then
|
|
echo "No .mbtiles files found!"
|
|
exit 1
|
|
fi
|
|
FILENAMES=()
|
|
for file in "${FILES[@]}"; do
|
|
FILENAMES+=("$(basename "$file")")
|
|
done
|
|
echo "Select an MBTiles file:"
|
|
for i in "${!FILENAMES[@]}"; do
|
|
echo "$((i+1))) ${FILENAMES[$i]}"
|
|
done
|
|
read -p "Enter the number of your choice: " SELECTION
|
|
if ! [[ "$SELECTION" =~ ^[0-9]+$ ]] || [ "$SELECTION" -lt 1 ] || [ "$SELECTION" -gt "${#FILENAMES[@]}" ]; then
|
|
echo "Invalid selection!"
|
|
exit 1
|
|
fi
|
|
MBTILES_FILE="${FILENAMES[$((SELECTION-1))]}"
|
|
sed -i "s|^MBTILES_FILE=.*|MBTILES_FILE=${MBTILES_FILE}|" .env
|
|
echo "Updated .env with MBTILES_FILE=${MBTILES_FILE}"
|
|
|
|
CONFIG_FILE="data/config.json"
|
|
if [ ! -f "$CONFIG_FILE" ]; then
|
|
echo "Error: config.json not found!"
|
|
exit 1
|
|
fi
|
|
|
|
STYLES_PATH=$(jq -r '.options.paths.styles' "$CONFIG_FILE")
|
|
STYLE_FILES=($(jq -r '.styles[].style' "$CONFIG_FILE"))
|
|
FONTS_PATH=$(jq -r '.options.paths.fonts' "$CONFIG_FILE")
|
|
|
|
MISSING_FILES=()
|
|
for file in "${STYLE_FILES[@]}"; do
|
|
ABSOLUTE_PATH="$DATA_PATH/$STYLES_PATH/$file"
|
|
|
|
if [ ! -f "$ABSOLUTE_PATH" ]; then
|
|
MISSING_FILES+=("$ABSOLUTE_PATH")
|
|
fi
|
|
done
|
|
|
|
if [ ${#MISSING_FILES[@]} -gt 0 ]; then
|
|
echo -e "\nMissing style files:"
|
|
for file in "${MISSING_FILES[@]}"; do
|
|
echo " - $file"
|
|
done
|
|
exit 1
|
|
else
|
|
echo "All style files are present."
|
|
fi
|
|
|
|
echo -e "\n Downloading fonts"
|
|
wget https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/test_data.zip
|
|
unzip test_data.zip
|
|
rm -rf test_data.zip
|
|
rm -rf styles
|
|
rm -f zurich_switzerland.mbtiles
|
|
rm -f config.json
|
|
mv fonts $DATA_PATH
|
|
|
|
echo "Starting container"
|
|
sudo docker compose up -d tile-server |