Implement .env configuration
This commit is contained in:
@@ -5,6 +5,48 @@ HOST="${MCP_HOST:-0.0.0.0}"
|
||||
PORT="${MCP_PORT:-8787}"
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
load_env_file() {
|
||||
local env_file="$1"
|
||||
local line key value first last comment_start
|
||||
|
||||
[[ -r "${env_file}" ]] || return 0
|
||||
|
||||
while IFS= read -r line || [[ -n "${line}" ]]; do
|
||||
line="${line#"${line%%[![:space:]]*}"}"
|
||||
line="${line%"${line##*[![:space:]]}"}"
|
||||
|
||||
[[ -z "${line}" || "${line}" == \#* || "${line}" != *=* ]] && continue
|
||||
|
||||
key="${line%%=*}"
|
||||
value="${line#*=}"
|
||||
key="${key%"${key##*[![:space:]]}"}"
|
||||
value="${value#"${value%%[![:space:]]*}"}"
|
||||
value="${value%"${value##*[![:space:]]}"}"
|
||||
|
||||
[[ "${key}" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
|
||||
[[ -v "${key}" ]] && continue
|
||||
|
||||
first="${value:0:1}"
|
||||
last="${value: -1}"
|
||||
if [[ "${#value}" -ge 2 && ( ( "${first}" == "'" && "${last}" == "'" ) || ( "${first}" == '"' && "${last}" == '"' ) ) ]]; then
|
||||
value="${value:1:${#value}-2}"
|
||||
else
|
||||
comment_start="${value%%" #"*}"
|
||||
if [[ "${comment_start}" != "${value}" ]]; then
|
||||
value="${comment_start}"
|
||||
value="${value%"${value##*[![:space:]]}"}"
|
||||
fi
|
||||
fi
|
||||
|
||||
export "${key}=${value}"
|
||||
done < "${env_file}"
|
||||
}
|
||||
|
||||
load_env_file "${ROOT}/.env"
|
||||
|
||||
HOST="${MCP_HOST:-${HOST}}"
|
||||
PORT="${MCP_PORT:-${PORT}}"
|
||||
|
||||
if [[ "${MCP_ALLOW_UNAUTHENTICATED:-}" != "1" && -z "${MCP_AUTH_TOKEN:-}" ]]; then
|
||||
MCP_AUTH_TOKEN="$(php -r 'echo bin2hex(random_bytes(24));')"
|
||||
export MCP_AUTH_TOKEN
|
||||
|
||||
Reference in New Issue
Block a user