forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_source_local_dev_env.sh
More file actions
75 lines (68 loc) · 2.48 KB
/
Copy path_source_local_dev_env.sh
File metadata and controls
75 lines (68 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
# Export provider secrets for harness shell preflight (safe parse — never `source` the file).
# Child processes receive a fully-formed env from the harness (OMI_HARNESS_INSTANCE set);
# they do not load backend/.env or stage files on disk.
_repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
_stage="${OMI_ENV_STAGE:-}"
if [ -z "$_stage" ] && [ "${PROVIDER_MODE:-}" = "offline" ]; then
_stage="offline"
fi
if [ -z "$_stage" ]; then
_stage="local"
fi
case "$_stage" in
local) _secrets_file="$_repo_root/backend/.env.local-dev" ;;
offline) _secrets_file="$_repo_root/backend/.env.offline" ;;
*)
case "$_stage" in
dev) _secrets_file="$_repo_root/backend/.env.dev" ;;
prod) _secrets_file="$_repo_root/backend/.env.prod" ;;
*)
echo "Unknown OMI_ENV_STAGE=${_stage} (expected local, offline, dev, or prod)" >&2
exit 1
;;
esac
;;
esac
_ALLOWED_KEYS=" PROVIDER_MODE OPENAI_API_KEY DEEPGRAM_API_KEY GEMINI_API_KEY ANTHROPIC_API_KEY "
_load_allowed_secrets() {
local file="$1"
local line key value
[ -f "$file" ] || return 0
while IFS= read -r line || [ -n "$line" ]; do
line="${line#"${line%%[![:space:]]*}"}"
line="${line%"${line##*[![:space:]]}"}"
[ -z "$line" ] && continue
[[ "$line" == \#* ]] && continue
[[ "$line" != *=* ]] && continue
key="${line%%=*}"
value="${line#*=}"
key="${key#"${key%%[![:space:]]*}"}"
key="${key%"${key##*[![:space:]]}"}"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
if [[ "$value" == \"*\" && "$value" == *\" ]]; then
value="${value:1:${#value}-2}"
elif [[ "$value" == \'*\' && "$value" == *\' ]]; then
value="${value:1:${#value}-2}"
fi
case "$_ALLOWED_KEYS" in
*" $key "*) printf -v "$key" '%s' "$value"; export "$key" ;;
esac
done < "$file"
}
_load_allowed_secrets "$_secrets_file"
# Optional personal overrides for manual standalone backend runs only.
_personal_env="$_repo_root/backend/.env"
if [ -f "$_personal_env" ] && [ "$_personal_env" != "$_secrets_file" ] && [ -z "${OMI_HARNESS_INSTANCE:-}" ]; then
_load_allowed_secrets "$_personal_env"
fi
export OMI_ENV_STAGE="$_stage"
# Firebase emulators require JDK 21+ on PATH (Homebrew keg-only install).
for _java_home in /opt/homebrew/opt/openjdk@21 /opt/homebrew/opt/openjdk@17; do
if [ -x "$_java_home/bin/java" ]; then
export JAVA_HOME="$_java_home"
export PATH="$_java_home/bin:$PATH"
break
fi
done