-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·54 lines (44 loc) · 1.37 KB
/
entrypoint.sh
File metadata and controls
executable file
·54 lines (44 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
48
49
50
51
52
53
54
#!/bin/bash
function initial_config {
env_vars=(
"MAIL_DOMAIN"
"SUBMISSION_HOST"
"TLS_CERT_FILE"
"TLS_KEY_FILE"
)
dovecot_staging_directory=/tmp/dovecot_staging
dovecot_directory=/etc/dovecot
# Check if all required variables have been set
for each in "${env_vars[@]}"; do
if ! [[ -v $each ]]; then
echo "$each has not been set!"
var_unset=true
fi
done
if [ $var_unset ]; then
echo "One or more required variables are unset. You must set them before setup can continue."
exit 1
fi
echo "Preparing configuration files"
env_vars_subst=${env_vars[@]/#/$}
cd $dovecot_staging_directory && find . -type f -exec sh -c "cat {} | envsubst '$env_vars_subst' > $dovecot_directory/{}" \;
echo "Setting permissions"
addgroup -g 5000 vmail
adduser -D -u 5000 -G vmail -s /usr/bin/nologin -h /var/mail vmail
echo "Creating folder for sieve"
mkdir $dovecot_directory/sieve
chown 5000:5000 $dovecot_directory/sieve
echo "Cleaning up"
cd $dovecot_directory
rm -r $dovecot_staging_directory
echo 'This file is used by docker to check whether the container has already been configured' > $configured_file
}
configured_file=/etc/docker.configured
if [ -f "$configured_file" ]; then
echo "Starting dovecot..."
else
echo "Configuring dovecot..."
initial_config
echo "Done. Starting dovecot..."
fi
exec /usr/sbin/dovecot -F