<commit_before>#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset

source_data_dir=${SOURCE_DATA_DIR:-/data}
dest_data_dir=${DEST_DATA_DIR:-/project}
port=${PORT:-80}
cache_size=${CACHE_SIZE:-10}
source_cache_size=${SOURCE_CACHE_SIZE:-10}

# find first tm2 project
if [ "$(ls -A $source_data_dir)" ]; then
    if [ -d "$source_data_dir"/*.tm2 ]; then
        for _project_dir in "$source_data_dir"/*.tm2; do
            [ -d "${_project_dir}" ] && project_dir="${_project_dir}" && break
        done
    else
        mbtiles_file=""
        for _mbtiles_file in "$source_data_dir"/*.mbtiles; do
            mbtiles_file="${_mbtiles_file}"
            break
        done

        if [ -f "$mbtiles_file" ]; then
            echo "The mbtiles file is now served with X-Ray styles"

            exec tessera "xray+mbtiles://$mbtiles_file" \
                --port $port \
                --cache-size $cache_size \
                --source-cache-size $source_cache_size
        else
            echo "No tm2 projects found. Please add a tm2 project to your mounted folder."
            exit 404
        fi
    fi
else
    echo "No tm2 projects found. Please mount the $source_data_dir volume to a folder containing tm2 projects."
    exit 404
fi

# find all tm2 projects but only the first project will be hosted for now
project_name="${project_dir##*/}"
project_config_file="${project_dir%%/}/project.yml"
vectortiles_name="${project_name%.tm2}.mbtiles"
mbtiles_file="${source_data_dir%%/}/$vectortiles_name"

echo "Found project ${project_name}"

# project config will be copied to new folder because we
# modify the source configuration of the style and don't want
# that to effect the original file
dest_project_dir="${dest_data_dir%%/}/$project_name"
dest_project_config_file="${dest_project_dir%%/}/project.yml"
cp -rf "$project_dir" "$dest_project_dir"

# project.yml is single source of truth, therefore the mapnik
# stylesheet is not necessary
rm -f "${dest_project_dir%%/}/project.xml"

# replace external vector tile sources with mbtiles source
# this allows developing rapidyl with an external source and then use the
# mbtiles for dependency free deployment
if [ -f "$mbtiles_file" ]; then
    echo "Associating $vectortiles_name with $project_name"
    replace_expr="s|source: \".*\"|source: \"mbtiles://$mbtiles_file\"|g"
    sed -e "$replace_expr" $project_config_file > $dest_project_config_file
else
    echo "No mbtiles matching project $project_name found."
    echo "Please name the mbtiles file the same as your style project."
    exit 500
fi

exec tessera "tmstyle://$dest_project_dir" \
    --port $port \
    --cache-size $cache_size \
    --source-cache-size $source_cache_size<commit_msg>Use upper case for bash vars<commit_after>#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset

SOURCE_DATA_DIR=${SOURCE_DATA_DIR:-/data}
DEST_DATA_DIR=${DEST_DATA_DIR:-/project}
PORT=${PORT:-80}
CACHE_SIZE=${CACHE_SIZE:-10}
SOURCE_CACHE_SIZE=${SOURCE_CACHE_SIZE:-10}

# find first tm2 project
if [ "$(ls -A $SOURCE_DATA_DIR)" ]; then
    if [ -d "$SOURCE_DATA_DIR"/*.tm2 ]; then
        for _PROJECT_DIR in "$SOURCE_DATA_DIR"/*.tm2; do
            [ -d "${_PROJECT_DIR}" ] && PROJECT_DIR="${_PROJECT_DIR}" && break
        done
    else
        MBTILES_FILE=""
        for _MBTILES_FILE in "$SOURCE_DATA_DIR"/*.mbtiles; do
            MBTILES_FILE="${_MBTILES_FILE}"
            break
        done

        if [ -f "$MBTILES_FILE" ]; then
            echo "The mbtiles file is now served with X-Ray styles"

            exec tessera "xray+mbtiles://$MBTILES_FILE" \
                --PORT $PORT \
                --cache-size $CACHE_SIZE \
                --source-cache-size $SOURCE_CACHE_SIZE
        else
            echo "No tm2 projects found. Please add a tm2 project to your mounted folder."
            exit 404
        fi
    fi
else
    echo "No tm2 projects found. Please mount the $SOURCE_DATA_DIR volume to a folder containing tm2 projects."
    exit 404
fi

# find all tm2 projects but only the first project will be hosted for now
PROJECT_NAME="${PROJECT_DIR##*/}"
PROJECT_CONFIG_FILE="${PROJECT_DIR%%/}/project.yml"
VECTORTILES_NAME="${PROJECT_NAME%.tm2}.mbtiles"
MBTILES_FILE="${SOURCE_DATA_DIR%%/}/$VECTORTILES_NAME"

echo "Found project ${PROJECT_NAME}"

# project config will be copied to new folder because we
# modify the source configuration of the style and don't want
# that to effect the original file
DEST_PROJECT_DIR="${DEST_DATA_DIR%%/}/$PROJECT_NAME"
DEST_PROJECT_CONFIG_FILE="${DEST_PROJECT_DIR%%/}/project.yml"
cp -rf "$PROJECT_DIR" "$DEST_PROJECT_DIR"

# project.yml is single source of truth, therefore the mapnik
# stylesheet is not necessary
rm -f "${DEST_PROJECT_DIR%%/}/project.xml"

# replace external vector tile sources with mbtiles source
# this allows developing rapidyl with an external source and then use the
# mbtiles for dependency free deployment
if [ -f "$MBTILES_FILE" ]; then
    echo "Associating $VECTORTILES_NAME with $PROJECT_NAME"
    replace_expr="s|source: \".*\"|source: \"mbtiles://$MBTILES_FILE\"|g"
    sed -e "$replace_expr" $PROJECT_CONFIG_FILE > $DEST_PROJECT_CONFIG_FILE
else
    echo "No mbtiles matching project $PROJECT_NAME found."
    echo "Please name the mbtiles file the same as your style project."
    exit 500
fi

exec tessera "tmstyle://$DEST_PROJECT_DIR" \
    --PORT $PORT \
    --cache-size $CACHE_SIZE \
    --source-cache-size $SOURCE_CACHE_SIZE
{'fraction_non_alphanumeric': 0.11402383134738772, 'fraction_numerical': 0.008799266727772686, 'mean_word_length': 3.3164556962025316, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6673118', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1764, 'n_words': 512}