Enable scheduled backups of ncue.net databases and git.ncue.net repository mirrors via .env-driven shell scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
25 lines
801 B
Bash
Executable File
25 lines
801 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# 프로젝트 루트 .env에서 KEY=VALUE 줄만 export (섹션 헤더 [..]·주석 무시)
|
|
load_project_env() {
|
|
local env_file="$1"
|
|
if [[ ! -f "$env_file" ]]; then
|
|
echo "load_project_env: .env not found: $env_file" >&2
|
|
return 1
|
|
fi
|
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
|
line="${line#"${line%%[![:space:]]*}"}"
|
|
[[ -z "$line" || "$line" == \#* ]] && continue
|
|
[[ "$line" == \[* ]] && continue
|
|
if [[ "$line" =~ ^([A-Za-z_][A-Za-z0-9_]*)=(.*)$ ]]; then
|
|
local key="${BASH_REMATCH[1]}"
|
|
local val="${BASH_REMATCH[2]}"
|
|
if [[ "$val" =~ ^\"(.*)\"$ ]]; then
|
|
val="${BASH_REMATCH[1]}"
|
|
elif [[ "$val" =~ ^\'(.*)\'$ ]]; then
|
|
val="${BASH_REMATCH[1]}"
|
|
fi
|
|
export "$key=$val"
|
|
fi
|
|
done < "$env_file"
|
|
}
|