-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure_env.sh
More file actions
executable file
·90 lines (69 loc) · 2.44 KB
/
configure_env.sh
File metadata and controls
executable file
·90 lines (69 loc) · 2.44 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
log_error() {
echo -e "$1" >&2
}
log_info() {
echo -e "$1"
}
prompt_numeric_input() {
local prompt="$1"
local default_value="$2"
local input
while true; do
read -p "$prompt" input
if [[ -z "$input" ]]; then
echo "$default_value"
return 0
fi
if [[ "$input" =~ ^[0-9]+$ ]]; then
echo "$input"
return 0
fi
log_error "Invalid input. Please enter a numeric value."
done
}
configure_environment() {
local DEFAULT_HOST="db"
local DEFAULT_POSTGRES_PORT="5432"
local DEFAULT_POSTGRES_USER="postgres"
local DEFAULT_POSTGRES_PASSWORD="postgres"
local DEFAULT_POSTGRES_DB="crm_rules"
local DEFAULT_REDIS_PORT="6379"
local DEFAULT_REDIS_HOST="redis"
local DEFAULT_REDIS_CHANNEL="crm_rules"
log_info "Configuring environment variables..."
log_info "Tip: Press Enter to use default values or skip configuration"
read -p "Enter Postgres host [$DEFAULT_HOST]: " POSTGRES_HOST
POSTGRES_HOST=${POSTGRES_HOST:-$DEFAULT_HOST}
POSTGRES_PORT=$(prompt_numeric_input "Enter Postgres port [$DEFAULT_POSTGRES_PORT]: " "$DEFAULT_POSTGRES_PORT")
read -p "Enter Postgres user [$DEFAULT_POSTGRES_USER]: " POSTGRES_USER
POSTGRES_USER=${POSTGRES_USER:-$DEFAULT_POSTGRES_USER}
read -p "Enter Postgres password [$DEFAULT_POSTGRES_PASSWORD]: " POSTGRES_PASSWORD
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-$DEFAULT_POSTGRES_PASSWORD}
read -p "Enter Postgres database [$DEFAULT_POSTGRES_DB]: " POSTGRES_DB
POSTGRES_DB=${POSTGRES_DB:-$DEFAULT_POSTGRES_DB}
read -p "Enter Redis host [$DEFAULT_REDIS_HOST]: " REDIS_HOST
REDIS_HOST=${REDIS_HOST:-$DEFAULT_REDIS_HOST}
REDIS_PORT=$(prompt_numeric_input "Enter Redis port [$DEFAULT_REDIS_PORT]: " "$DEFAULT_REDIS_PORT")
read -p "Enter Redis channel [$DEFAULT_REDIS_CHANNEL]: " REDIS_CHANNEL
REDIS_CHANNEL=${REDIS_CHANNEL:-$DEFAULT_REDIS_CHANNEL}
cat > .env << EOF
POSTGRES_HOST=$POSTGRES_HOST
POSTGRES_PORT=$POSTGRES_PORT
POSTGRES_USER=$POSTGRES_USER
POSTGRES_PASSWORD=$POSTGRES_PASSWORD
POSTGRES_DB=$POSTGRES_DB
REDIS_HOST=$REDIS_HOST
REDIS_PORT=$REDIS_PORT
REDIS_CHANNEL=$REDIS_CHANNEL
EOF
log_info "Environment configuration complete."
}
main() {
if [[ ! -f .env ]] || [[ ! -s .env ]]; then
configure_environment
else
log_info ".env file already exists and is not empty. Skipping configuration."
fi
}
main