-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathentrypoint-utils.sh
More file actions
executable file
·125 lines (101 loc) · 2.77 KB
/
Copy pathentrypoint-utils.sh
File metadata and controls
executable file
·125 lines (101 loc) · 2.77 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
CONFIG_PREFIX="ESPOCRM_CONFIG_"
# This allows containers with /var/www/html directory mounted directly to keep running.
# To be removed in future releases.
isLegacy() {
awk '$2 == "/var/www/html" { found = 1; exit 0 } END { if (!found) { exit 1 } }' /proc/mounts
}
exitIfNotReady() {
if isLegacy; then
return
fi
bin/command app-check >/dev/null 2>&1 || {
echo >&2 "Waiting for the main container to be ready..."
exit 0
}
}
applyConfigEnv() {
if isLegacy; then
return
fi
local name
local value
compgen -v | while read -r name; do
if [[ $name != "$CONFIG_PREFIX"* ]]; then
continue
fi
value="${!name}"
saveConfigValue "$name" "$value"
done
}
verifyDatabaseReady() {
for i in {1..20}; do
[ "$(bin/command db:check 2>/dev/null)" = "OK" ] && return 0
echo >&2 "Waiting for database connection (attempt $i/20)..."
sleep 3
done
echo >&2 "error: Database connection failed."
return 1
}
normalizeConfigParamName() {
local value="$1"
if [[ "${value^^}" == "${CONFIG_PREFIX^^}"* ]]; then
value="${value:${#CONFIG_PREFIX}}"
fi
value="${value,,}"
value="${value//__/.}"
local result="" i=0 next
while [[ $i -lt ${#value} ]]; do
if [[ "${value:$i:1}" == "_" ]]; then
next="${value:$((i+1)):1}"
if [[ "$next" =~ [a-zA-Z] ]]; then
result+="${next^^}"
i=$(( i + 2 ))
continue
fi
fi
result+="${value:$i:1}"
i=$(( i + 1 ))
done
echo "$result"
}
normalizeConfigParamValue() {
local value="$1"
local trimmed="$value"
trimmed="${trimmed#"${trimmed%%[![:space:]]*}"}"
trimmed="${trimmed%"${trimmed##*[![:space:]]}"}"
if [[ "${trimmed:0:1}" == "'" && "${trimmed: -1:1}" == "'" ]]; then
local inner="${trimmed:1:${#trimmed}-2}"
local pat="\\\\"
pat+="'"
local repl="'"
echo "${inner//$pat/$repl}"
return
fi
echo "$value"
}
saveConfigValue() {
local name="$1"
local value="$2"
local normalizedName
normalizedName=$(normalizeConfigParamName "$name")
local normalizedValue
normalizedValue=$(normalizeConfigParamValue "$value")
bin/command config:set "$normalizedName" "$normalizedValue" --type=auto
}
setEnvValue() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
printf >&2 "error: Both $var and $fileVar are set"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}