-
-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathstart.sh
More file actions
48 lines (38 loc) · 1.37 KB
/
start.sh
File metadata and controls
48 lines (38 loc) · 1.37 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
#!/bin/sh
set +x
file_vars=$(env | grep -E '^[^=]+_FILE=' | cut -d'=' -f1)
for file_var in $file_vars; do
# Derive base var name (remove _FILE suffix; POSIX supports %)
base_var="${file_var%_FILE}"
# Get the file path (use eval for indirect access)
eval "file_path=\${$file_var:-}"
# Check if base var is set (eval to check existence)
eval "base_value=\${$base_var:-}"
if [ -n "$base_value" ]; then
echo "Skipped $base_var: already set" >&2
continue
fi
if [ -z "$file_path" ]; then
echo "Skipped $base_var: $file_var is empty/unset" >&2
continue
fi
if [ ! -f "$file_path" ]; then
echo "Skipped $base_var: file does not exist ($file_path)" >&2
continue
fi
if [ ! -r "$file_path" ]; then
echo "Skipped $base_var: file not readable ($file_path)" >&2
continue
fi
# Read file contents, trim trailing newlines (POSIX: use sed)
value=$(cat "$file_path" | sed 's/[\n\r]*$//')
# Export the base var (use eval to set dynamically)
eval "$base_var=\"$value\""
export "$base_var"
echo "Set $base_var from $file_var ($file_path)" >&2
done
if [ -z "$DATABASE_URL" ]; then
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_CONTAINER_NAME}:${POSTGRES_PORT}/${POSTGRES_DB}
fi
echo "Starting web server"
node server.js