schon/scripts/Unix/export-environment-file.sh
Egor fureunoir Gorbunov 1e8d053ab6 Features: 1) OS-specific scripts for deployments.
2) Healthcheck improvements.
Fixes: merge_recently_viewed for UserViewSet
2025-06-11 02:54:46 +03:00

26 lines
635 B
Bash

#!/usr/bin/env bash
set -euo pipefail
env_file='.env'
if [[ ! -f $env_file ]]; then
echo "Error: $env_file not found in the current directory." >&2
return 1 2>/dev/null || exit 1
fi
while IFS= read -r line || [[ -n $line ]]; do
line="${line#"${line%%[![:space:]]*}"}"
line="${line%"${line##*[![:space:]]}"}"
[[ -z $line || $line == \#* ]] && continue
[[ $line != *"="* ]] && continue
key="${line%%=*}"
value="${line#*=}"
if [[ ( $value == \"*\" && $value == *\" ) || ( $value == \'*\' && $value == *\' ) ]]; then
value="${value:1:-1}"
fi
export "$key"="$value"
echo "Exported $key"
done < "$env_file"