mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
Move setup process via script into container (#2174)
Decoupling setup process from `setup.sh` script by introducing a setup script _inside_ the container that coordinates the setup process. **This is not a breaking change**. This way, we do not have to keep track of versions of `setup.sh`. This change brings the additional benefit for Kubernetes users to be able to make use of `setup` now, without the need for `setup.sh`. --- * move setup process into container; setup.sh versioning not needed anymore * add tilde functionality to docs Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com> Co-authored-by: Casper <casperklein@users.noreply.github.com>
This commit is contained in:
parent
c267d8a990
commit
c7e4981945
25
README.md
25
README.md
|
@ -76,28 +76,23 @@ All workflows are using the tagging convention listed below. It is subsequently
|
||||||
|
|
||||||
### Get the tools
|
### Get the tools
|
||||||
|
|
||||||
Download `docker-compose.yml` and `mailserver.env`
|
Since Docker Mailserver `v10.2.0`, `setup.sh` functionality is included within the Docker image. The external convenience script is no longer required if you prefer using `docker exec <CONTAINER NAME> setup <COMMAND>` instead.
|
||||||
|
|
||||||
|
> **Note:** If you're using Docker or Docker Compose and are new to Docker Mailserver, it is recommended to use the script `setup.sh` for convenience.
|
||||||
|
|
||||||
``` BASH
|
``` BASH
|
||||||
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/docker-compose.yml
|
DMS_GITHUB_URL='https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master'
|
||||||
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/mailserver.env
|
wget "${DMS_GITHUB_URL}/docker-compose.yml"
|
||||||
```
|
wget "${DMS_GITHUB_URL}/mailserver.env"
|
||||||
|
wget "${DMS_GITHUB_URL}/setup.sh"
|
||||||
and the `setup.sh` **in the correct version**
|
|
||||||
|
|
||||||
``` BASH
|
|
||||||
# if you're using :edge as the image tag
|
|
||||||
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/setup.sh
|
|
||||||
# if you're using :latest (= :10.1.1) as the image tag
|
|
||||||
wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/v10.1.2/setup.sh
|
|
||||||
|
|
||||||
chmod a+x ./setup.sh
|
chmod a+x ./setup.sh
|
||||||
|
|
||||||
# and make yourself familiar with the script
|
|
||||||
./setup.sh help
|
./setup.sh help
|
||||||
```
|
```
|
||||||
|
|
||||||
**Make sure to get the `setup.sh` that comes with the release you're using**. Look up the release and the git commit on which this release is based upon by selecting the appropriate tag on GitHub. This can done with the "Switch branches/tags" button on GitHub, choosing the right tag. This is done in order to rule out possible inconsistencies between versions.
|
If no `docker-mailserver` container is running, any `./setup.sh` command will check online for the `:latest` image tag (the current stable release), performing a `pull` if necessary followed by running the command in a temporary container.
|
||||||
|
|
||||||
|
**NOTE** _If you're using Docker Mailserver version `v10.1.x` or below_, you will need to get `setup.sh` with a specific version. Substitute `<VERSION>` with the mail server version you're using: `wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/<VERSION>/setup.sh`.
|
||||||
|
|
||||||
### Create a docker-compose environment
|
### Create a docker-compose environment
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
title: Your best friend setup.sh
|
title: Your best friend setup.sh
|
||||||
hide:
|
hide:
|
||||||
- toc # Hide Table of Contents for this page
|
- toc
|
||||||
---
|
---
|
||||||
|
|
||||||
[`setup.sh`][github-file-setupsh] is an administration script that helps with the most common tasks, including initial configuration. It is intended to be used from the host machine, _not_ from within your running container.
|
[`setup.sh`][github-file-setupsh] is an administration script that helps with the most common tasks, including initial configuration. It is intended to be used from the host machine, _not_ from within your running container.
|
||||||
|
@ -13,13 +13,9 @@ wget https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/maste
|
||||||
chmod a+x ./setup.sh
|
chmod a+x ./setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! info
|
|
||||||
|
|
||||||
Make sure to get the `setup.sh` that comes with the release you're using. Look up the release and the git commit on which this release is based upon by selecting the appropriate tag on GitHub. This can done with the "Switch branches/tags" button on GitHub, choosing the right tag. This is done in order to rule out possible inconsistencies between versions.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Run `./setup.sh help` and you'll get some usage information:
|
Run `./setup.sh help` and you'll get ~~all you have ever wanted~~ some usage information:
|
||||||
|
|
||||||
```TXT
|
```TXT
|
||||||
SETUP(1)
|
SETUP(1)
|
||||||
|
@ -55,28 +51,6 @@ VERSION
|
||||||
following URL, where TAG looks like 'vX.X.X':
|
following URL, where TAG looks like 'vX.X.X':
|
||||||
https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/TAG/setup.sh
|
https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/TAG/setup.sh
|
||||||
|
|
||||||
OPTIONS
|
|
||||||
Config path, container or image adjustments
|
|
||||||
-i IMAGE_NAME
|
|
||||||
Provides the name of the docker-mailserver image. The default value is
|
|
||||||
docker.io/mailserver/docker-mailserver:latest
|
|
||||||
|
|
||||||
-c CONTAINER_NAME
|
|
||||||
Provides the name of the running container.
|
|
||||||
|
|
||||||
-p PATH
|
|
||||||
Provides the config folder path. The default is
|
|
||||||
/home/maxwell/Dokumente/github/docker-mailserver/config/
|
|
||||||
|
|
||||||
SELinux
|
|
||||||
-z
|
|
||||||
Allows container access to the bind mount content that is shared among
|
|
||||||
multiple containers on a SELinux-enabled host.
|
|
||||||
|
|
||||||
-Z
|
|
||||||
Allows container access to the bind mount content that is private and
|
|
||||||
unshared with other containers on a SELinux-enabled host.
|
|
||||||
|
|
||||||
[SUB]COMMANDS
|
[SUB]COMMANDS
|
||||||
COMMAND email :=
|
COMMAND email :=
|
||||||
./setup.sh email add <EMAIL ADDRESS> [<PASSWORD>]
|
./setup.sh email add <EMAIL ADDRESS> [<PASSWORD>]
|
||||||
|
@ -122,6 +96,28 @@ EXAMPLES
|
||||||
This will provide you with a detailed explanation on how to use the
|
This will provide you with a detailed explanation on how to use the
|
||||||
config dkim command, showing what arguments can be passed and what they do.
|
config dkim command, showing what arguments can be passed and what they do.
|
||||||
|
|
||||||
|
OPTIONS
|
||||||
|
Config path, container or image adjustments
|
||||||
|
-i IMAGE_NAME
|
||||||
|
Provides the name of the docker-mailserver image. The default value is
|
||||||
|
docker.io/mailserver/docker-mailserver:latest
|
||||||
|
|
||||||
|
-c CONTAINER_NAME
|
||||||
|
Provides the name of the running container.
|
||||||
|
|
||||||
|
-p PATH
|
||||||
|
Provides the config folder path to the temporary container
|
||||||
|
(does not work if docker-mailserver container already exists).
|
||||||
|
|
||||||
|
SELinux
|
||||||
|
-z
|
||||||
|
Allows container access to the bind mount content that is shared among
|
||||||
|
multiple containers on a SELinux-enabled host.
|
||||||
|
|
||||||
|
-Z
|
||||||
|
Allows container access to the bind mount content that is private and
|
||||||
|
unshared with other containers on a SELinux-enabled host.
|
||||||
|
|
||||||
EXIT STATUS
|
EXIT STATUS
|
||||||
Exit status is 0 if the command was successful. If there was an unexpected error, an error
|
Exit status is 0 if the command was successful. If there was an unexpected error, an error
|
||||||
message is shown describing the error. In case of an error, the script will exit with exit
|
message is shown describing the error. In case of an error, the script will exit with exit
|
||||||
|
|
|
@ -75,6 +75,7 @@ markdown_extensions:
|
||||||
- pymdownx.superfences
|
- pymdownx.superfences
|
||||||
- pymdownx.magiclink
|
- pymdownx.magiclink
|
||||||
- pymdownx.inlinehilite
|
- pymdownx.inlinehilite
|
||||||
|
- pymdownx.tilde
|
||||||
- pymdownx.emoji:
|
- pymdownx.emoji:
|
||||||
emoji_index: !!python/name:materialx.emoji.twemoji
|
emoji_index: !!python/name:materialx.emoji.twemoji
|
||||||
emoji_generator: !!python/name:materialx.emoji.to_svg
|
emoji_generator: !!python/name:materialx.emoji.to_svg
|
||||||
|
|
318
setup.sh
318
setup.sh
|
@ -1,37 +1,63 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
# version v0.3.0 stable
|
# version v1.0.0
|
||||||
# executed manually / via Make
|
# executed manually / via Make
|
||||||
# task wrapper for various setup scripts
|
# task wrapper for various setup scripts
|
||||||
|
|
||||||
SCRIPT='setup.sh'
|
SCRIPT='setup.sh'
|
||||||
|
|
||||||
WHITE="\e[37m"
|
|
||||||
RED="\e[31m"
|
|
||||||
PURPLE="\e[35m"
|
|
||||||
YELLOW="\e[93m"
|
|
||||||
ORANGE="\e[38;5;214m"
|
|
||||||
CYAN="\e[96m"
|
|
||||||
BLUE="\e[34m"
|
|
||||||
LBLUE="\e[94m"
|
|
||||||
BOLD="\e[1m"
|
|
||||||
RESET="\e[0m"
|
|
||||||
|
|
||||||
set -euEo pipefail
|
set -euEo pipefail
|
||||||
trap '__log_err "${FUNCNAME[0]:-?}" "${BASH_COMMAND:-?}" "${LINENO:-?}" "${?:-?}"' ERR
|
trap '__err "${FUNCNAME[0]:-?}" "${BASH_COMMAND:-?}" "${LINENO:-?}" "${?:-?}"' ERR
|
||||||
|
|
||||||
function __log_err
|
function __err
|
||||||
{
|
{
|
||||||
printf "\n--- ${BOLD}${RED}UNCHECKED ERROR${RESET}\n%s\n%s\n%s\n%s\n\n" \
|
[[ ${4} -gt 1 ]] && exit 1
|
||||||
" - script = ${SCRIPT:-${0}}" \
|
|
||||||
" - function = ${1} / ${2}" \
|
|
||||||
" - line = ${3}" \
|
|
||||||
" - exit code = ${4}" >&2
|
|
||||||
|
|
||||||
printf "Make sure you use a version of this script that matches
|
local ERR_MSG='--- \e[31m\e[1mUNCHECKED ERROR\e[0m'
|
||||||
the version / tag of docker-mailserver. Please read the
|
ERR_MSG+="\n - script = ${SCRIPT:-${0}}"
|
||||||
'Get the tools' section in the README on GitHub careful-
|
ERR_MSG+="\n - function = ${1} / ${2}"
|
||||||
ly and use ./setup.sh help and read the VERSION section.\n" >&2
|
ERR_MSG+="\n - line = ${3}"
|
||||||
|
ERR_MSG+="\n - exit code = ${4}"
|
||||||
|
ERR_MSG+='\n'
|
||||||
|
|
||||||
|
echo -e "${ERR_MSG}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _show_local_usage
|
||||||
|
{
|
||||||
|
local WHITE="\e[37m"
|
||||||
|
local ORANGE="\e[38;5;214m"
|
||||||
|
local LBLUE="\e[94m"
|
||||||
|
local RESET="\e[0m"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
printf "${ORANGE}OPTIONS${RESET}
|
||||||
|
${LBLUE}Config path, container or image adjustments${RESET}
|
||||||
|
-i IMAGE_NAME
|
||||||
|
Provides the name of the docker-mailserver image. The default value is
|
||||||
|
${WHITE}docker.io/mailserver/docker-mailserver:latest${RESET}
|
||||||
|
|
||||||
|
-c CONTAINER_NAME
|
||||||
|
Provides the name of the running container.
|
||||||
|
|
||||||
|
-p PATH
|
||||||
|
Provides the config folder path to the temporary container (does not work if docker-mailserver container already exists).
|
||||||
|
|
||||||
|
${LBLUE}SELinux${RESET}
|
||||||
|
-z
|
||||||
|
Allows container access to the bind mount content that is shared among
|
||||||
|
multiple containers on a SELinux-enabled host.
|
||||||
|
|
||||||
|
-Z
|
||||||
|
Allows container access to the bind mount content that is private and
|
||||||
|
unshared with other containers on a SELinux-enabled host.
|
||||||
|
|
||||||
|
${ORANGE}EXIT STATUS${RESET}
|
||||||
|
Exit status is 0 if the command was successful. If there was an unexpected error, an error
|
||||||
|
message is shown describing the error. In case of an error, the script will exit with exit
|
||||||
|
status 1.
|
||||||
|
|
||||||
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _get_absolute_script_directory
|
function _get_absolute_script_directory
|
||||||
|
@ -39,7 +65,8 @@ function _get_absolute_script_directory
|
||||||
if [[ "$(uname)" == "Darwin" ]]
|
if [[ "$(uname)" == "Darwin" ]]
|
||||||
then
|
then
|
||||||
readlink() {
|
readlink() {
|
||||||
greadlink "${@:+$@}" # Requires coreutils
|
# requires coreutils
|
||||||
|
greadlink "${@:+$@}"
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
if dirname "$(readlink -f "${0}")" &>/dev/null
|
if dirname "$(readlink -f "${0}")" &>/dev/null
|
||||||
|
@ -70,7 +97,9 @@ function _check_root
|
||||||
{
|
{
|
||||||
if [[ ${EUID} -ne 0 ]]
|
if [[ ${EUID} -ne 0 ]]
|
||||||
then
|
then
|
||||||
echo "Curently docker-mailserver doesn't support podman's rootless mode, please run this script as root user."
|
echo "Curently, DMS doesn't support podman's rootless mode.
|
||||||
|
Please run this script as root user."
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -81,7 +110,7 @@ function _update_config_path
|
||||||
then
|
then
|
||||||
VOLUME=$(${CRI} inspect "${CONTAINER_NAME}" \
|
VOLUME=$(${CRI} inspect "${CONTAINER_NAME}" \
|
||||||
--format="{{range .Mounts}}{{ println .Source .Destination}}{{end}}" | \
|
--format="{{range .Mounts}}{{ println .Source .Destination}}{{end}}" | \
|
||||||
grep "/tmp/docker-mailserver$" 2>/dev/null)
|
grep "/tmp/docker-mailserver$" 2>/dev/null || :)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n ${VOLUME} ]]
|
if [[ -n ${VOLUME} ]]
|
||||||
|
@ -90,137 +119,6 @@ function _update_config_path
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _inspect
|
|
||||||
{
|
|
||||||
if _docker_image_exists "${IMAGE_NAME}"
|
|
||||||
then
|
|
||||||
echo "Image: ${IMAGE_NAME}"
|
|
||||||
else
|
|
||||||
echo "Image: '${IMAGE_NAME}' can’t be found."
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n ${CONTAINER_NAME} ]]
|
|
||||||
then
|
|
||||||
echo "Container: ${CONTAINER_NAME}"
|
|
||||||
echo "Config mount: ${CONFIG_PATH}"
|
|
||||||
else
|
|
||||||
echo "Container: Not running, please start docker-mailserver."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function _usage
|
|
||||||
{
|
|
||||||
# shellcheck disable=SC2059
|
|
||||||
printf "${PURPLE}SETUP${RED}(${YELLOW}1${RED})
|
|
||||||
|
|
||||||
${ORANGE}NAME${RESET}
|
|
||||||
${SCRIPT:-${0}} - docker-mailserver administration script
|
|
||||||
|
|
||||||
${ORANGE}SYNOPSIS${RESET}
|
|
||||||
./${SCRIPT:-${0}} [ OPTIONS${RED}...${RESET} ] COMMAND [ help ${RED}|${RESET} ARGUMENTS${RED}...${RESET} ]
|
|
||||||
|
|
||||||
COMMAND ${RED}:=${RESET} { email ${RED}|${RESET} alias ${RED}|${RESET} quota ${RED}|${RESET} config ${RED}|${RESET} relay ${RED}|${RESET} debug } SUBCOMMAND
|
|
||||||
|
|
||||||
${ORANGE}DESCRIPTION${RESET}
|
|
||||||
This is the main administration script that you use for all interactions with your
|
|
||||||
mail server. Setup, configuration and much more is done with this script.
|
|
||||||
|
|
||||||
Please note that this script executes most of its commands inside the running 'mailserver' container itself.
|
|
||||||
If it cannot find a running container, it will attempt to run one using any available tags
|
|
||||||
which include label=org.opencontainers.image.title=\"docker-mailserver\" and then run the necessary commands.
|
|
||||||
If the tag for the container is not found, this script will pull the ${WHITE}:latest${RESET} tag of
|
|
||||||
${WHITE}docker.io/mailserver/docker-mailserver${RESET}. This tag refers to the latest release,
|
|
||||||
see the tagging convention in the README under
|
|
||||||
${BLUE}https://github.com/docker-mailserver/docker-mailserver/blob/master/README.md${RESET}
|
|
||||||
|
|
||||||
You will be able to see detailed information about the script you're invoking and
|
|
||||||
its arguments by appending ${WHITE}help${RESET} after your command. Currently, this
|
|
||||||
does not work with all scripts.
|
|
||||||
|
|
||||||
${ORANGE}VERSION${RESET}
|
|
||||||
The current version of this script is backwards compatible with versions of
|
|
||||||
${WHITE}docker-mailserver${RESET} ${BOLD}after${RESET} ${BLUE}8.0.1${RESET}. In case that there is not a more recent release,
|
|
||||||
this script is currently only working with the ${WHITE}:edge${RESET} tag.
|
|
||||||
|
|
||||||
You can download the script for your release by substituting TAG from the
|
|
||||||
following URL, where TAG looks like 'vX.X.X':
|
|
||||||
https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/TAG/setup.sh
|
|
||||||
|
|
||||||
${ORANGE}OPTIONS${RESET}
|
|
||||||
${LBLUE}Config path, container or image adjustments${RESET}
|
|
||||||
-i IMAGE_NAME
|
|
||||||
Provides the name of the docker-mailserver image. The default value is
|
|
||||||
${WHITE}docker.io/mailserver/docker-mailserver:latest${RESET}
|
|
||||||
|
|
||||||
-c CONTAINER_NAME
|
|
||||||
Provides the name of the running container.
|
|
||||||
|
|
||||||
-p PATH
|
|
||||||
Provides the config folder path to the temporary container (does not work if docker-mailserver container already exists). The default is
|
|
||||||
${WHITE}${DIR}/config/${RESET}
|
|
||||||
|
|
||||||
${LBLUE}SELinux${RESET}
|
|
||||||
-z
|
|
||||||
Allows container access to the bind mount content that is shared among
|
|
||||||
multiple containers on a SELinux-enabled host.
|
|
||||||
|
|
||||||
-Z
|
|
||||||
Allows container access to the bind mount content that is private and
|
|
||||||
unshared with other containers on a SELinux-enabled host.
|
|
||||||
|
|
||||||
${RED}[${ORANGE}SUB${RED}]${ORANGE}COMMANDS${RESET}
|
|
||||||
${LBLUE}COMMAND${RESET} email ${RED}:=${RESET}
|
|
||||||
${0} email ${CYAN}add${RESET} <EMAIL ADDRESS> [<PASSWORD>]
|
|
||||||
${0} email ${CYAN}update${RESET} <EMAIL ADDRESS> [<PASSWORD>]
|
|
||||||
${0} email ${CYAN}del${RESET} [ OPTIONS${RED}...${RESET} ] <EMAIL ADDRESS> [ <EMAIL ADDRESS>${RED}...${RESET} ]
|
|
||||||
${0} email ${CYAN}restrict${RESET} <add${RED}|${RESET}del${RED}|${RESET}list> <send${RED}|${RESET}receive> [<EMAIL ADDRESS>]
|
|
||||||
${0} email ${CYAN}list${RESET}
|
|
||||||
|
|
||||||
${LBLUE}COMMAND${RESET} alias ${RED}:=${RESET}
|
|
||||||
${0} alias ${CYAN}add${RESET} <EMAIL ADDRESS> <RECIPIENT>
|
|
||||||
${0} alias ${CYAN}del${RESET} <EMAIL ADDRESS> <RECIPIENT>
|
|
||||||
${0} alias ${CYAN}list${RESET}
|
|
||||||
|
|
||||||
${LBLUE}COMMAND${RESET} quota ${RED}:=${RESET}
|
|
||||||
${0} quota ${CYAN}set${RESET} <EMAIL ADDRESS> [<QUOTA>]
|
|
||||||
${0} quota ${CYAN}del${RESET} <EMAIL ADDRESS>
|
|
||||||
|
|
||||||
${LBLUE}COMMAND${RESET} config ${RED}:=${RESET}
|
|
||||||
${0} config ${CYAN}dkim${RESET} [ ARGUMENTS${RED}...${RESET} ]
|
|
||||||
|
|
||||||
${LBLUE}COMMAND${RESET} relay ${RED}:=${RESET}
|
|
||||||
${0} relay ${CYAN}add-domain${RESET} <DOMAIN> <HOST> [<PORT>]
|
|
||||||
${0} relay ${CYAN}add-auth${RESET} <DOMAIN> <USERNAME> [<PASSWORD>]
|
|
||||||
${0} relay ${CYAN}exclude-domain${RESET} <DOMAIN>
|
|
||||||
|
|
||||||
${LBLUE}COMMAND${RESET} debug ${RED}:=${RESET}
|
|
||||||
${0} debug ${CYAN}fetchmail${RESET}
|
|
||||||
${0} debug ${CYAN}fail2ban${RESET} [unban <IP>]
|
|
||||||
${0} debug ${CYAN}show-mail-logs${RESET}
|
|
||||||
${0} debug ${CYAN}inspect${RESET}
|
|
||||||
${0} debug ${CYAN}login${RESET} <COMMANDS>
|
|
||||||
|
|
||||||
${ORANGE}EXAMPLES${RESET}
|
|
||||||
${WHITE}./setup.sh email add test@domain.tld${RESET}
|
|
||||||
Add the email account ${WHITE}test@domain.tld${RESET}. You will be prompted
|
|
||||||
to input a password afterwards since no password was supplied.
|
|
||||||
|
|
||||||
${WHITE}./setup.sh config dkim keysize 2048 domain 'whoami.com,whoareyou.org'${RESET}
|
|
||||||
Creates keys of length 2048 but in an LDAP setup where domains are not known to
|
|
||||||
Postfix by default, so you need to provide them yourself in a comma-separated list.
|
|
||||||
|
|
||||||
${WHITE}./setup.sh config dkim help${RESET}
|
|
||||||
This will provide you with a detailed explanation on how to use the ${WHITE}
|
|
||||||
config dkim${RESET} command, showing what arguments can be passed and what they do.
|
|
||||||
|
|
||||||
${ORANGE}EXIT STATUS${RESET}
|
|
||||||
Exit status is 0 if the command was successful. If there was an unexpected error, an error
|
|
||||||
message is shown describing the error. In case of an error, the script will exit with exit
|
|
||||||
status 1.
|
|
||||||
|
|
||||||
"
|
|
||||||
}
|
|
||||||
|
|
||||||
function _docker_image_exists
|
function _docker_image_exists
|
||||||
{
|
{
|
||||||
${CRI} history -q "${1}" &>/dev/null
|
${CRI} history -q "${1}" &>/dev/null
|
||||||
|
@ -236,9 +134,9 @@ function _docker_image
|
||||||
${CRI} pull "${IMAGE_NAME}"
|
${CRI} pull "${IMAGE_NAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
${CRI} run --rm \
|
${CRI} run --rm "${USE_TTY}" \
|
||||||
-v "${CONFIG_PATH}:/tmp/docker-mailserver${USE_SELINUX}" \
|
-v "${CONFIG_PATH}:/tmp/docker-mailserver${USE_SELINUX}" \
|
||||||
"${USE_TTY}" "${IMAGE_NAME}" "${@:+$@}"
|
"${IMAGE_NAME}" "${@:+$@}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _docker_container
|
function _docker_container
|
||||||
|
@ -247,7 +145,8 @@ function _docker_container
|
||||||
then
|
then
|
||||||
${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" "${@:+$@}"
|
${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" "${@:+$@}"
|
||||||
else
|
else
|
||||||
# If no container yet, run a temporary one: https://github.com/docker-mailserver/docker-mailserver/pull/1874#issuecomment-809781531
|
# if no container is running, run a temporary one:
|
||||||
|
# https://github.com/docker-mailserver/docker-mailserver/pull/1874#issuecomment-809781531
|
||||||
_docker_image "${@:+$@}"
|
_docker_image "${@:+$@}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -263,7 +162,7 @@ function _main
|
||||||
_check_root
|
_check_root
|
||||||
else
|
else
|
||||||
echo "No supported Container Runtime Interface detected."
|
echo "No supported Container Runtime Interface detected."
|
||||||
exit 10
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
INFO=$(${CRI} ps --no-trunc --format "{{.Image}};{{.Names}}" --filter \
|
INFO=$(${CRI} ps --no-trunc --format "{{.Image}};{{.Names}}" --filter \
|
||||||
|
@ -288,33 +187,29 @@ function _main
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local OPTIND
|
local OPTIND
|
||||||
while getopts ":c:i:p:hzZ" OPT
|
while getopts ":c:i:p:zZ" OPT
|
||||||
do
|
do
|
||||||
case ${OPT} in
|
case ${OPT} in
|
||||||
i ) IMAGE_NAME="${OPTARG}" ;;
|
( i ) IMAGE_NAME="${OPTARG}" ;;
|
||||||
z ) USE_SELINUX=":z" ;;
|
( z | Z ) USE_SELINUX=":${OPTARG}" ;;
|
||||||
Z ) USE_SELINUX=":Z" ;;
|
( c ) CONTAINER_NAME="${OPTARG}" ;;
|
||||||
c )
|
|
||||||
# container specified, connect to running instance
|
|
||||||
CONTAINER_NAME="${OPTARG}"
|
|
||||||
;;
|
|
||||||
|
|
||||||
p )
|
( p )
|
||||||
case "${OPTARG}" in
|
case "${OPTARG}" in
|
||||||
/* ) WISHED_CONFIG_PATH="${OPTARG}" ;;
|
( /* ) WISHED_CONFIG_PATH="${OPTARG}" ;;
|
||||||
* ) WISHED_CONFIG_PATH="${DIR}/${OPTARG}" ;;
|
( * ) WISHED_CONFIG_PATH="${DIR}/${OPTARG}" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ ! -d ${WISHED_CONFIG_PATH} ]]
|
if [[ ! -d ${WISHED_CONFIG_PATH} ]]
|
||||||
then
|
then
|
||||||
echo "Directory doesn't exist"
|
echo "Specified directory '${WISHED_CONFIG_PATH}' doesn't exist" >&2
|
||||||
_usage
|
exit 1
|
||||||
exit 40
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
* )
|
( * )
|
||||||
echo "Invalid option: -${OPT}" >&2
|
echo "Invalid option: -${OPT}" >&2
|
||||||
|
exit 1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
@ -335,75 +230,10 @@ function _main
|
||||||
CONFIG_PATH=${WISHED_CONFIG_PATH}
|
CONFIG_PATH=${WISHED_CONFIG_PATH}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
_docker_container setup "${@:+$@}"
|
||||||
|
[[ ${1} == 'help' ]] && _show_local_usage
|
||||||
|
|
||||||
case ${1:-} in
|
return 0
|
||||||
|
|
||||||
email )
|
|
||||||
case ${2:-} in
|
|
||||||
add ) shift 2 ; _docker_container addmailuser "${@:+$@}" ;;
|
|
||||||
update ) shift 2 ; _docker_container updatemailuser "${@:+$@}" ;;
|
|
||||||
del ) shift 2 ; _docker_container delmailuser "${@:+$@}" ;;
|
|
||||||
restrict ) shift 2 ; _docker_container restrict-access "${@:+$@}" ;;
|
|
||||||
list ) _docker_container listmailuser ;;
|
|
||||||
* ) _usage ;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
|
|
||||||
alias )
|
|
||||||
case ${2:-} in
|
|
||||||
add ) shift 2 ; _docker_container addalias "${1}" "${2}" ;;
|
|
||||||
del ) shift 2 ; _docker_container delalias "${1}" "${2}" ;;
|
|
||||||
list ) shift 2 ; _docker_container listalias ;;
|
|
||||||
* ) _usage ;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
|
|
||||||
quota )
|
|
||||||
case ${2:-} in
|
|
||||||
set ) shift 2 ; _docker_container setquota "${@:+$@}" ;;
|
|
||||||
del ) shift 2 ; _docker_container delquota "${@:+$@}" ;;
|
|
||||||
* ) _usage ;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
|
|
||||||
config )
|
|
||||||
case ${2:-} in
|
|
||||||
dkim ) shift 2 ; _docker_container open-dkim "${@:+$@}" ;;
|
|
||||||
* ) _usage ;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
|
|
||||||
relay )
|
|
||||||
case ${2:-} in
|
|
||||||
add-domain ) shift 2 ; _docker_container addrelayhost "${@:+$@}" ;;
|
|
||||||
add-auth ) shift 2 ; _docker_container addsaslpassword "${@:+$@}" ;;
|
|
||||||
exclude-domain ) shift 2 ; _docker_container excluderelaydomain "${@:+$@}" ;;
|
|
||||||
* ) _usage ;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
|
|
||||||
debug )
|
|
||||||
case ${2:-} in
|
|
||||||
fetchmail ) _docker_container debug-fetchmail ;;
|
|
||||||
fail2ban ) shift 2 ; _docker_container fail2ban "${@:+$@}" ;;
|
|
||||||
show-mail-logs ) _docker_container cat /var/log/mail/mail.log ;;
|
|
||||||
inspect ) _inspect ;;
|
|
||||||
login )
|
|
||||||
shift 2
|
|
||||||
if [[ -z ${1:-} ]]
|
|
||||||
then
|
|
||||||
_docker_container /bin/bash
|
|
||||||
else
|
|
||||||
_docker_container /bin/bash -c "${@:+$@}"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
* ) _usage ; exit 1 ;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
|
|
||||||
help ) _usage ;;
|
|
||||||
* ) _usage ; exit 1 ;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_main "${@:+$@}"
|
_main "${@:+$@}"
|
||||||
|
|
171
target/bin/setup
Normal file
171
target/bin/setup
Normal file
|
@ -0,0 +1,171 @@
|
||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
SCRIPT='setup'
|
||||||
|
|
||||||
|
set -euE -o pipefail
|
||||||
|
|
||||||
|
function _usage
|
||||||
|
{
|
||||||
|
local WHITE="\e[37m"
|
||||||
|
local RED="\e[31m"
|
||||||
|
local PURPLE="\e[35m"
|
||||||
|
local YELLOW="\e[93m"
|
||||||
|
local ORANGE="\e[38;5;214m"
|
||||||
|
local CYAN="\e[96m"
|
||||||
|
local BLUE="\e[34m"
|
||||||
|
local LBLUE="\e[94m"
|
||||||
|
local RESET="\e[0m"
|
||||||
|
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
printf "${PURPLE}SETUP${RED}(${YELLOW}1${RED})
|
||||||
|
|
||||||
|
${ORANGE}NAME${RESET}
|
||||||
|
${SCRIPT:-${0}} - docker-mailserver administration & configuration script
|
||||||
|
|
||||||
|
${ORANGE}SYNOPSIS${RESET}
|
||||||
|
./${SCRIPT:-${0}} [ OPTIONS${RED}...${RESET} ] COMMAND [ help ${RED}|${RESET} ARGUMENTS${RED}...${RESET} ]
|
||||||
|
|
||||||
|
COMMAND ${RED}:=${RESET} { email ${RED}|${RESET} alias ${RED}|${RESET} quota ${RED}|${RESET} config ${RED}|${RESET} relay ${RED}|${RESET} debug } SUBCOMMAND
|
||||||
|
|
||||||
|
${ORANGE}DESCRIPTION${RESET}
|
||||||
|
This is the main administration script that you use for all interactions with your
|
||||||
|
mail server. Setup, configuration and much more is done with this script.
|
||||||
|
|
||||||
|
Please note that this script executes most of its commands inside the running 'mailserver'
|
||||||
|
container itself. If it cannot find a running container, it will attempt to run one using
|
||||||
|
any available tags which include label=org.opencontainers.image.title=\"docker-mailserver\"
|
||||||
|
and then run the necessary commands. If the tag for the container is not found, this script
|
||||||
|
will pull the ${WHITE}:latest${RESET} tag of ${WHITE}docker.io/mailserver/docker-mailserver${RESET}.This tag refers to the
|
||||||
|
latest release, see the tagging convention in the README under
|
||||||
|
${BLUE}https://github.com/docker-mailserver/docker-mailserver/blob/master/README.md${RESET}
|
||||||
|
|
||||||
|
You will be able to see detailed information about the script you're invoking and their
|
||||||
|
arguments by appending ${WHITE}help${RESET} after your command. Currently, this does not work with all scripts.
|
||||||
|
|
||||||
|
${RED}[${ORANGE}SUB${RED}]${ORANGE}COMMANDS${RESET}
|
||||||
|
${LBLUE}COMMAND${RESET} email ${RED}:=${RESET}
|
||||||
|
${0} email ${CYAN}add${RESET} <EMAIL ADDRESS> [<PASSWORD>]
|
||||||
|
${0} email ${CYAN}update${RESET} <EMAIL ADDRESS> [<PASSWORD>]
|
||||||
|
${0} email ${CYAN}del${RESET} [ OPTIONS${RED}...${RESET} ] <EMAIL ADDRESS> [ <EMAIL ADDRESS>${RED}...${RESET} ]
|
||||||
|
${0} email ${CYAN}restrict${RESET} <add${RED}|${RESET}del${RED}|${RESET}list> <send${RED}|${RESET}receive> [<EMAIL ADDRESS>]
|
||||||
|
${0} email ${CYAN}list${RESET}
|
||||||
|
|
||||||
|
${LBLUE}COMMAND${RESET} alias ${RED}:=${RESET}
|
||||||
|
${0} alias ${CYAN}add${RESET} <EMAIL ADDRESS> <RECIPIENT>
|
||||||
|
${0} alias ${CYAN}del${RESET} <EMAIL ADDRESS> <RECIPIENT>
|
||||||
|
${0} alias ${CYAN}list${RESET}
|
||||||
|
|
||||||
|
${LBLUE}COMMAND${RESET} quota ${RED}:=${RESET}
|
||||||
|
${0} quota ${CYAN}set${RESET} <EMAIL ADDRESS> [<QUOTA>]
|
||||||
|
${0} quota ${CYAN}del${RESET} <EMAIL ADDRESS>
|
||||||
|
|
||||||
|
${LBLUE}COMMAND${RESET} config ${RED}:=${RESET}
|
||||||
|
${0} config ${CYAN}dkim${RESET} [ ARGUMENTS${RED}...${RESET} ]
|
||||||
|
|
||||||
|
${LBLUE}COMMAND${RESET} relay ${RED}:=${RESET}
|
||||||
|
${0} relay ${CYAN}add-domain${RESET} <DOMAIN> <HOST> [<PORT>]
|
||||||
|
${0} relay ${CYAN}add-auth${RESET} <DOMAIN> <USERNAME> [<PASSWORD>]
|
||||||
|
${0} relay ${CYAN}exclude-domain${RESET} <DOMAIN>
|
||||||
|
|
||||||
|
${LBLUE}COMMAND${RESET} debug ${RED}:=${RESET}
|
||||||
|
${0} debug ${CYAN}fetchmail${RESET}
|
||||||
|
${0} debug ${CYAN}fail2ban${RESET} [unban <IP>]
|
||||||
|
${0} debug ${CYAN}show-mail-logs${RESET}
|
||||||
|
${0} debug ${CYAN}inspect${RESET}
|
||||||
|
${0} debug ${CYAN}login${RESET} <COMMANDS>
|
||||||
|
|
||||||
|
${ORANGE}EXAMPLES${RESET}
|
||||||
|
${WHITE}./setup.sh email add test@domain.tld${RESET}
|
||||||
|
Add the email account ${WHITE}test@domain.tld${RESET}. You will be prompted
|
||||||
|
to input a password afterwards since no password was supplied.
|
||||||
|
|
||||||
|
${WHITE}./setup.sh config dkim keysize 2048 domain 'whoami.com,whoareyou.org'${RESET}
|
||||||
|
Creates keys of length 2048 but in an LDAP setup where domains are not known to
|
||||||
|
Postfix by default, so you need to provide them yourself in a comma-separated list.
|
||||||
|
|
||||||
|
${WHITE}./setup.sh config dkim help${RESET}
|
||||||
|
This will provide you with a detailed explanation on how to use the ${WHITE}
|
||||||
|
config dkim${RESET} command, showing what arguments can be passed and what they do.
|
||||||
|
|
||||||
|
"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _invalid_command
|
||||||
|
{
|
||||||
|
echo "The command '${*}' is invalid.
|
||||||
|
Use \`./setup.sh help\` to get an overview of all commands." >&2
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
|
||||||
|
function _main
|
||||||
|
{
|
||||||
|
case ${1:-} in
|
||||||
|
|
||||||
|
email )
|
||||||
|
case ${2:-} in
|
||||||
|
add ) shift 2 ; addmailuser "${@}" ;;
|
||||||
|
update ) shift 2 ; updatemailuser "${@}" ;;
|
||||||
|
del ) shift 2 ; delmailuser "${@}" ;;
|
||||||
|
restrict ) shift 2 ; restrict-access "${@}" ;;
|
||||||
|
list ) listmailuser ;;
|
||||||
|
* ) _invalid_command "${1}" "${2}" ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
alias )
|
||||||
|
case ${2:-} in
|
||||||
|
add ) shift 2 ; addalias "${1}" "${2}" ;;
|
||||||
|
del ) shift 2 ; delalias "${1}" "${2}" ;;
|
||||||
|
list ) shift 2 ; listalias ;;
|
||||||
|
* ) _invalid_command "${1}" "${2}" ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
quota )
|
||||||
|
case ${2:-} in
|
||||||
|
set ) shift 2 ; setquota "${@}" ;;
|
||||||
|
del ) shift 2 ; delquota "${@}" ;;
|
||||||
|
* ) _invalid_command "${1}" "${2}" ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
config )
|
||||||
|
case ${2:-} in
|
||||||
|
dkim ) shift 2 ; open-dkim "${@}" ;;
|
||||||
|
* ) _invalid_command "${1}" "${2}" ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
relay )
|
||||||
|
case ${2:-} in
|
||||||
|
add-domain ) shift 2 ; addrelayhost "${@}" ;;
|
||||||
|
add-auth ) shift 2 ; addsaslpassword "${@}" ;;
|
||||||
|
exclude-domain ) shift 2 ; excluderelaydomain "${@}" ;;
|
||||||
|
* ) _invalid_command "${1}" "${2}" ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
debug )
|
||||||
|
case ${2:-} in
|
||||||
|
fetchmail ) debug-fetchmail ;;
|
||||||
|
fail2ban ) shift 2 ; fail2ban "${@}" ;;
|
||||||
|
show-mail-logs ) cat /var/log/mail/mail.log ;;
|
||||||
|
login )
|
||||||
|
shift 2
|
||||||
|
if [[ -z ${1:-} ]]
|
||||||
|
then
|
||||||
|
/bin/bash
|
||||||
|
else
|
||||||
|
/bin/bash -c "${@}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
* ) _invalid_command "${1}" "${2}" ;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
|
||||||
|
help ) _usage ;;
|
||||||
|
* ) _invalid_command "${*}" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_main "${@}"
|
|
@ -943,13 +943,13 @@ EOF
|
||||||
@test "setup.sh :: exit with error when no arguments provided" {
|
@test "setup.sh :: exit with error when no arguments provided" {
|
||||||
run ./setup.sh
|
run ./setup.sh
|
||||||
assert_failure
|
assert_failure
|
||||||
assert_line --index 2 " setup.sh - docker-mailserver administration script"
|
assert_line --index 0 --partial "The command '' is invalid."
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "setup.sh :: exit with error when wrong arguments provided" {
|
@test "setup.sh :: exit with error when wrong arguments provided" {
|
||||||
run ./setup.sh lol troll
|
run ./setup.sh lol troll
|
||||||
assert_failure
|
assert_failure
|
||||||
assert_line --index 2 " setup.sh - docker-mailserver administration script"
|
assert_line --index 0 --partial "The command 'lol troll' is invalid."
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking setup.sh: setup.sh email add and login" {
|
@test "checking setup.sh: setup.sh email add and login" {
|
||||||
|
@ -1126,17 +1126,13 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# debug
|
# debug
|
||||||
|
|
||||||
@test "checking setup.sh: setup.sh debug fetchmail" {
|
@test "checking setup.sh: setup.sh debug fetchmail" {
|
||||||
run ./setup.sh -c mail debug fetchmail
|
run ./setup.sh -c mail debug fetchmail
|
||||||
assert_failure 11
|
assert_failure
|
||||||
assert_output --partial "fetchmail: normal termination, status 11"
|
assert_output --partial "fetchmail: normal termination, status 11"
|
||||||
}
|
}
|
||||||
@test "checking setup.sh: setup.sh debug inspect" {
|
|
||||||
run ./setup.sh -c mail debug inspect
|
|
||||||
assert_success
|
|
||||||
assert_line --index 0 "Image: ${NAME}"
|
|
||||||
assert_line --index 1 "Container: mail"
|
|
||||||
}
|
|
||||||
@test "checking setup.sh: setup.sh debug login ls" {
|
@test "checking setup.sh: setup.sh debug login ls" {
|
||||||
run ./setup.sh -c mail debug login ls
|
run ./setup.sh -c mail debug login ls
|
||||||
assert_success
|
assert_success
|
||||||
|
|
Loading…
Reference in a new issue