forked from arugifa/simplelogin-postfix-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·98 lines (84 loc) · 3.17 KB
/
entrypoint.sh
File metadata and controls
executable file
·98 lines (84 loc) · 3.17 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
#!/usr/bin/env bash
# Supported compatibility modes for Simplelogin
readonly VALID_COMPATIBILITY_MODES=("v3" "v4")
# POstfix Custom Data Directory
readonly DEFAULT_POSTFIX_CUSTOM_DATA_DIRECTORY="/etc/postfix/custom-data"
# This function reads the docker secrets based variables defined with pattern *_FILE into the normal variables
# usage: file_env VAR [DEFAULT]
# ie: file_env 'DB_PASSWORD' 'default_password'
# (will allow for "$DB_PASSWORD_FILE" to fill in the value of
# "$DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo "Both $var and $fileVar are set (but are exclusive)"
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
# A simple utility function to check if a given value is present in array
# The first argument is the value to be checked
# The second argument is a bash array
# Example:
# readonly MODES=("up" "down")
# local current_mode="up"
# if ! contains_element "${current_mode}" "${MODES[@]}"; then
# echo "Current mode is not valid value ${current_mode}"
# echo "Valid values are: (${MODES[*]})"
# exit -1
# else
# echo "Found value: ${current_mode}"
# fi
contains_element () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
setup_postfix_custom_data () {
if [[ ! "${POSTFIX_CUSTOM_DATA_DIRECTORY}" ]]; then
export POSTFIX_CUSTOM_DATA_DIRECTORY="${DEFAULT_POSTFIX_CUSTOM_DATA_DIRECTORY}";
fi
mkdir -p ${POSTFIX_CUSTOM_DATA_DIRECTORY}
if [[ ! -f ${POSTFIX_CUSTOM_DATA_DIRECTORY}/aliases ]]; then
touch ${POSTFIX_CUSTOM_DATA_DIRECTORY}/aliases
postalias ${POSTFIX_CUSTOM_DATA_DIRECTORY}/aliases
fi
}
setup_dnsbl_reply_map () {
if [[ "${POSTFIX_DQN_KEY}" ]]; then
postmap lmdb:/etc/postfix/dnsbl-reply-map
fi
}
_main() {
# Each environment variable that supports the *_FILE pattern needs to be passed into the file_env() function.
file_env "DB_PASSWORD"
file_env "RELAY_HOST_PASSWORD"
setup_postfix_custom_data
# Test if SIMPLELOGIN_COMPATIBILITY_MODE option was not present, and set it to default v3.
if [[ ! "${SIMPLELOGIN_COMPATIBILITY_MODE}" ]] ; then
export SIMPLELOGIN_COMPATIBILITY_MODE="v3";
else
# Test that SIMPLELOGIN_COMPATIBILITY_MODE contains a valid value
if ! contains_element "${SIMPLELOGIN_COMPATIBILITY_MODE}" "${VALID_COMPATIBILITY_MODES[@]}"; then
echo "Simplelogin Compatibility Mode: ${SIMPLELOGIN_COMPATIBILITY_MODE} is not valid! Valid values are: (${VALID_COMPATIBILITY_MODES[*]})"
exit -1
else
echo "Simplelogin Compatibility Mode is set to: ${SIMPLELOGIN_COMPATIBILITY_MODE}"
fi
fi
if [[ -f ${TLS_KEY_FILE} && -f ${TLS_CERT_FILE} ]]; then
rm -f /etc/periodic/hourly/renew-postfix-tls
crond && python3 generate_config.py --postfix && setup_dnsbl_reply_map && postfix start-fg
else
python3 generate_config.py --certbot && certbot -n certonly; crond && python3 generate_config.py --postfix && setup_dnsbl_reply_map && postfix start-fg
fi
}
_main "$@"