[TOOLS][DOCKER] Add mail setup to configure

This commit is contained in:
margarida 2020-11-29 00:41:07 +00:00 committed by Hugo Sales
parent c36259f7c1
commit f3c3d80892
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0
7 changed files with 80 additions and 30 deletions

68
bin/configure vendored
View File

@ -85,7 +85,7 @@ fi
mkdir -p $ROOT/docker/bootstrap mkdir -p $ROOT/docker/bootstrap
cat > ./docker/bootstrap/bootstrap.env <<EOF cat > $ROOT/docker/bootstrap/bootstrap.env <<EOF
#!/bin/sh #!/bin/sh
email=${email} email=${email}
domain=${domain} domain=${domain}
@ -241,7 +241,7 @@ if [ "${dbms}" = 'mariadb' ]; then
exec 3>&- exec 3>&-
check_input $db_root_password check_input $db_root_password
cat > ./docker/db/db.env <<EOF cat > $ROOT/docker/db/db.env <<EOF
DBMS=${dbms} DBMS=${dbms}
MYSQL_ROOT_PASSWORD=${db_root_password} MYSQL_ROOT_PASSWORD=${db_root_password}
EOF EOF
@ -249,7 +249,7 @@ EOF
database_url="DATABASE_URL=mysql://${user}:${password}@db:3306/${db}" database_url="DATABASE_URL=mysql://${user}:${password}@db:3306/${db}"
else else
cat > ./docker/db/db.env <<EOF cat > $ROOT/docker/db/db.env <<EOF
DBMS=${dbms} DBMS=${dbms}
POSTGRES_USER=postgres POSTGRES_USER=postgres
POSTGRES_PASSWORD=${password} POSTGRES_PASSWORD=${password}
@ -264,7 +264,7 @@ echo "${database_url}" >> .env.local
mkdir -p $ROOT/docker/social mkdir -p $ROOT/docker/social
cat > ./docker/social/social.env <<EOF cat > $ROOT/docker/social/social.env <<EOF
SOCIAL_DBMS="${dbms}" SOCIAL_DBMS="${dbms}"
SOCIAL_DB="${db}" SOCIAL_DB="${db}"
SOCIAL_USER="${user}" SOCIAL_USER="${user}"
@ -321,10 +321,68 @@ esac
case $docker_compose in *"mail"*) case $docker_compose in *"mail"*)
$ROOT/docker/social/mail $ROOT/docker/social/mail
exec 3>&1
mail_domain_root=$(dialog \
--title "Configure Mail" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "E-mail domain root:" $HEIGHT $WIDTH \
2>&1 1>&3)
check_retval $?
exec 3>&-
check_input $mail_domain_root
exec 3>&1
mail_subdomain=$(dialog \
--title "Configure Mail" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "E-mail subdomain (can be empty):" $HEIGHT $WIDTH \
2>&1 1>&3)
check_retval $?
exec 3>&-
exec 3>&1
mail_user=$(dialog \
--title "Configure Mail" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "E-mail user (name without @domain): " $HEIGHT $WIDTH \
2>&1 1>&3)
check_retval $?
exec 3>&-
check_input $mail_user
exec 3>&1
mail_pass=$(dialog \
--title "Configure Mail" \
--clear \
--ok-label "Ok" \
--cancel-label "Exit" \
--inputbox "E-mail user password: " $HEIGHT $WIDTH \
2>&1 1>&3)
check_retval $?
exec 3>&-
check_input $mail_pass
mkdir -p $ROOT/docker/mail
cat > $ROOT/docker/mail/mail.env <<EOF
MAIL_DOMAIN_ROOT="${mail_domain_root}"
MAIL_SUBDOMAIN="${mail_subdomain}"
MAIL_USER="${mail_user}"
MAIL_PASSWORD="${mail_pass}"
EOF
$ROOT/docker/mail/setup.sh
esac esac
echo "volumes:\n database:" >> docker-compose.yaml echo "volumes:\n database:" >> docker-compose.yaml
clear

View File

View File

View File

View File

41
docker/mail/setup.sh Normal file → Executable file
View File

@ -1,39 +1,30 @@
#!/bin/sh #!/bin/sh
ROOT="$(git rev-parse --show-toplevel)"
. $ROOT/docker/mail/mail.env
cd "${0%/*}" cd "${0%/*}"
printf "Domain root: " if [ -z "${MAIL_SUBDOMAIN}" ]
read -r domain_root
printf "Subdomain (can be empty): "
read -r sub_domain
printf "E-mail user (name without @domain): "
read -r user
printf "E-mail pass: "
read -r pass
if [ -z "${sub_domain}" ]
then then
domain="${domain_root}" domain="${MAIL_DOMAIN_ROOT}"
else else
domain="${sub_domain}.${domain_root}" domain="${MAIL_SUBDOMAIN}.${MAIL_DOMAIN_ROOT}"
fi fi
PASSHASH=$(mkpasswd -m sha-512 -S "" -R 5000 ${MAIL_PASSWORD})
cat > mail.env <<EOF cat > mail.env <<EOF
#!/bin/sh #!/bin/sh
DOMAINNAME=${domain_root} DOMAINNAME=${MAIL_DOMAIN_ROOT}
MAILNAME=${domain} MAILNAME=${domain}
SSL_CERT=/etc/letsencrypt/live/${domain_root}/fullchain.pem SSL_CERT=/etc/letsencrypt/live/${MAIL_DOMAIN_ROOT}/fullchain.pem
SSL_KEY=/etc/letsencrypt/live/${domain_root}/privkey.pem SSL_KEY=/etc/letsencrypt/live/${MAIL_DOMAIN_ROOT}/privkey.pem
USER="${user}@${domain_root}" MAIL_USER="${MAIL_USER}"
USER="${MAIL_USER}@${MAIL_DOMAIN_ROOT}"
EOF EOF
DOMAINNAME="${domain_root}" . $ROOT/docker/mail/mail.env
MAILNAME="${domain}"
SSL_CERT="/etc/letsencrypt/live/${domain_root}/fullchain.pem"
SSL_KEY="/etc/letsencrypt/live/${domain_root}/privkey.pem"
USER="${user}@${DOMAINNAME}"
PASSHASH=$(mkpasswd -m sha-512 -S "" -R 5000 ${pass})
# Config postfix # Config postfix
sed -i -e "s#^\s*myhostname\s*=.*#myhostname = ${MAILNAME}#" config/postfix/main.cf sed -i -e "s#^\s*myhostname\s*=.*#myhostname = ${MAILNAME}#" config/postfix/main.cf
@ -53,5 +44,5 @@ sed -i -e "s/^.*#HOSTNAME/${MAILNAME}#HOSTNAME/" config/opendkim/TrustedHosts
touch config/aliases config/domains config/mailboxes config/passwd touch config/aliases config/domains config/mailboxes config/passwd
echo "${DOMAINNAME} #OK" > config/domains echo "${DOMAINNAME} #OK" > config/domains
echo "${USER} ${USER}" > config/aliases echo "${USER} ${USER}" > config/aliases
echo "${USER} ${DOMAINNAME}/${user}/" > config/mailboxes echo "${USER} ${DOMAINNAME}/${MAIL_USER}/" > config/mailboxes
echo "${USER}:${PASSHASH}" > config/passwd echo "${USER}:${PASSHASH}" > config/passwd

View File

@ -6,6 +6,7 @@ echo " mail:
- ./docker/mail/mail.env - ./docker/mail/mail.env
ports: ports:
- 25:25 - 25:25
- 110:110
- 143:143 - 143:143
- 587:587 - 587:587
- 993:993 - 993:993