From bf9a08740896c144a19221d6018f210cf7f1e33b Mon Sep 17 00:00:00 2001 From: Scott Cove Date: Tue, 18 Jan 2022 12:00:59 +1100 Subject: [PATCH] Added options to dockerfile to allow for use of commandline options --- Dockerfile | 9 +++- tools/docker-entrypoint.sh | 86 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100755 tools/docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 11bda23..b8f1623 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,17 @@ LABEL org.opencontainers.image.authors="Marcin Sztolcman " ARG VERSION=2.2.2 +USER root RUN addgroup -S sendria && adduser -S sendria -G sendria -WORKDIR /home/sendria +RUN apk add --no-cache --upgrade bash +RUN apk --update --no-cache --virtual build-dependencies add apache2-utils USER sendria +WORKDIR /home/sendria RUN python3 -m pip install --user sendria==$VERSION ENV PATH="/home/sendria/.local/bin:$PATH" +ENV SENDRIA_DATA_DIR="/home/sendria/data" +ADD tools /home/sendria/tools EXPOSE 1025 1080 -ENTRYPOINT [ "sendria", "--foreground", "--db=./mails.sqlite", "--smtp-ip=0.0.0.0", "--http-ip=0.0.0.0" ] +ENTRYPOINT [ "/home/sendria/tools/docker-entrypoint.sh" ] \ No newline at end of file diff --git a/tools/docker-entrypoint.sh b/tools/docker-entrypoint.sh new file mode 100755 index 0000000..3017bae --- /dev/null +++ b/tools/docker-entrypoint.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +declare -a cmd_opts + +# Make the data directory if it doesn't yet exist: +if [[ ! -d $SENDRIA_DATA_DIR ]]; then + mkdir -p $SENDRIA_DATA_DIR +fi + +### set any command line options that need setting: + +if [[ -n $DB_PATH ]] && [[ $DB_PATH =~ \.sqlite$ ]]; then + # Full path given + cmd_opts+=("--db=${DB_PATH}") +elif [[ -n $DB_PATH ]] && [[ ! $DB_PATH =~ \.sqlite$ ]] && [[ ! $DB_PATH =~ \/$ ]]; then + # No db file and no trailing slash + cmd_opts+=("--db=${DB_PATH}/mail.sqlite") +elif [[ -n $DB_PATH ]] && [[ ! $DB_PATH =~ \.sqlite$ ]] && [[ $DB_PATH =~ \/$ ]]; then + # No db file but with trailing slash + cmd_opts+=("--db=${DB_PATH}mail.sqlite") +else + cmd_opts+=("--db=${SENDRIA_DATA_DIR}/mail.sqlite") +fi + +if [[ -n $SMTP_USER ]] && [[ -n $SMTP_PASS ]]; then + # Both username and password given + htpasswd -bBc ${SENDRIA_DATA_DIR}/.smtp.htpasswd $SMTP_USER $SMTP_PASS + # echo "${SMTP_USER}:$(openssl passwd -5 ${SMTP_PASS})" >> ${SENDRIA_DATA_DIR}/.smtp.htpasswd + cmd_opts+=("--smtp-auth=${SENDRIA_DATA_DIR}/.smtp.htpasswd") +elif [[ -z $SMTP_USER ]] && [[ -n $SMTP_PASS ]]; then + # Only password given + # echo "smtp-user:$(openssl passwd -5 ${SMTP_PASS})" >> ${SENDRIA_DATA_DIR}/.smtp.htpasswd + htpasswd -bBc ${SENDRIA_DATA_DIR}/.smtp.htpasswd smtp-user $SMTP_PASS + cmd_opts+=("--smtp-auth=${SENDRIA_DATA_DIR}/.smtp.htpasswd") +elif [[ -n $SMTP_USER ]] && [[ -z $SMTP_PASS ]]; then + # Only username given + echo "smtp-user:" > ${SENDRIA_DATA_DIR}/.smtp.htpasswd + cmd_opts+=("--smtp-auth=${SENDRIA_DATA_DIR}/.smtp.htpasswd") +fi + +if [[ -n $HTTP_USER ]] && [[ -n $HTTP_PASS ]]; then + # Both username and password given + # echo "${HTTP_USER}:$(openssl passwd -5 ${HTTP_PASS})" >> ${SENDRIA_DATA_DIR}/.http.htpasswd + htpasswd -bBc ${SENDRIA_DATA_DIR}/.http.htpasswd $HTTP_USER $HTTP_PASS + cmd_opts+=("--http-auth=${SENDRIA_DATA_DIR}/.http.htpasswd") +elif [[ -z $HTTP_USER ]] && [[ -n $HTTP_PASS ]]; then + # Only password given + # echo "admin:$(openssl passwd -5 ${HTTP_PASS})" >> ${SENDRIA_DATA_DIR}/.http.htpasswd + htpasswd -bBc ${SENDRIA_DATA_DIR}/.http.htpasswd admin $HTTP_PASS + cmd_opts+=("--http-auth=${SENDRIA_DATA_DIR}/.http.htpasswd") +elif [[ -n $HTTP_USER ]] && [[ -z $HTTP_PASS ]]; then + # Only username given + echo "admin:" > ${SENDRIA_DATA_DIR}/.http.htpasswd + cmd_opts+=("--http-auth=${SENDRIA_DATA_DIR}/.http.htpasswd") +fi + +if [[ $DEBUG =~ ^[Tt][Rr][Uu][Ee]$ ]]; then + cmd_opts+=("-d") +fi + +if [[ $NO_QUIT =~ ^[Tt][Rr][Uu][Ee]$ ]]; then + cmd_opts+=("-n") +fi + +if [[ $NO_CLEAR =~ ^[Tt][Rr][Uu][Ee]$ ]]; then + cmd_opts+=("-c") +fi + +if [[ -n $TEMPLATE_NAME ]]; then + cmd_opts+=("--template-header-name=$TEMPLATE_NAME") +fi + +if [[ -n $TEMPLATE_URL ]]; then + cmd_opts+=("--template-header-url=$TEMPLATE_URL") +fi + + +# Run the command that needs running: +unset SMTP_PASS HTTP_PASS +echo "${cmd_opts[@]}" +if [[ -n $LOG_FILE ]]; then + sendria --foreground --smtp-ip=0.0.0.0 --http-ip=0.0.0.0 "${cmd_opts[@]}" | tee -a $LOG_FILE +else + sendria --foreground --smtp-ip=0.0.0.0 --http-ip=0.0.0.0 "${cmd_opts[@]}" +fi +exit $? \ No newline at end of file