2022-10-17 08:40:09 +00:00
|
|
|
#!/bin/bash
|
2016-08-28 19:10:25 +00:00
|
|
|
|
2021-09-19 14:47:08 +00:00
|
|
|
# version v1.0.0
|
2021-02-19 09:37:28 +00:00
|
|
|
# executed manually / via Make
|
2021-01-16 09:16:05 +00:00
|
|
|
# task wrapper for various setup scripts
|
2016-09-01 10:10:23 +00:00
|
|
|
|
2021-09-21 06:51:59 +00:00
|
|
|
CONFIG_PATH=
|
|
|
|
CONTAINER_NAME=
|
|
|
|
CRI=
|
|
|
|
DEFAULT_CONFIG_PATH=
|
|
|
|
DESIRED_CONFIG_PATH=
|
2022-05-05 08:28:38 +00:00
|
|
|
DIR=$(pwd)
|
2021-09-21 06:51:59 +00:00
|
|
|
DMS_CONFIG='/tmp/docker-mailserver'
|
|
|
|
IMAGE_NAME=
|
2023-04-10 09:37:25 +00:00
|
|
|
DEFAULT_IMAGE_NAME='ghcr.io/docker-mailserver/docker-mailserver:latest'
|
2021-09-21 06:51:59 +00:00
|
|
|
INFO=
|
|
|
|
PODMAN_ROOTLESS=false
|
|
|
|
USE_SELINUX=
|
|
|
|
USE_TTY=
|
|
|
|
VOLUME=
|
2020-10-04 17:34:15 +00:00
|
|
|
|
2022-05-05 15:48:21 +00:00
|
|
|
WHITE=$(echo -ne '\e[37m')
|
|
|
|
ORANGE=$(echo -ne '\e[38;5;214m')
|
|
|
|
LBLUE=$(echo -ne '\e[94m')
|
|
|
|
RESET=$(echo -ne '\e[0m')
|
2021-09-26 08:41:01 +00:00
|
|
|
|
2020-09-04 06:42:12 +00:00
|
|
|
set -euEo pipefail
|
2022-04-01 17:10:39 +00:00
|
|
|
shopt -s inherit_errexit 2>/dev/null || true
|
2021-09-19 14:47:08 +00:00
|
|
|
|
2023-05-25 23:01:41 +00:00
|
|
|
function _show_local_usage() {
|
2021-09-19 14:47:08 +00:00
|
|
|
# shellcheck disable=SC2059
|
2022-05-05 15:48:21 +00:00
|
|
|
printf '%s' "${ORANGE}OPTIONS${RESET}
|
2021-09-19 14:47:08 +00:00
|
|
|
${LBLUE}Config path, container or image adjustments${RESET}
|
|
|
|
-i IMAGE_NAME
|
docs(chore): Normalize for consistency (#2206)
"Brief" summary/overview of changes. See the PR discussion or individual commits from the PR for more details.
---
Only applies to the `docs/content/**` content (_and `setup` command_). `target/` and `test/` can be normalized at a later date.
* Normalize to `example.com`
- Domains normalized to `example.com`: `mywebserver.com`, `myserver.tld`, `domain.com`, `domain.tld`, `mydomain.net`, `my-domain.tld`, `my-domain.com`, `example.org`, `whoami.com`.
- Alternative domains normalized to `not-example.com`: `otherdomain.com`, `otherdomain.tld`, `domain2.tld`, `mybackupmx.com`, `whoareyou.org`.
- Email addresses normalized to `admin@example.com` (in `ssl.md`): `foo@bar.com`, `yourcurrentemail@gmail.com`, `email@email.com`, `admin@domain.tld`.
- Email addresses normalized to `external-account@gmail.com`: `bill@gates321boom.com`, `external@gmail.com`, `myemail@gmail.com`, `real-email-address@external-domain.com`.
- **`faq.md`:** A FAQ entry title with `sample.domain.com` changed to `subdomain.example.com`.
- **`mail-fetchmail.md`:** Config examples with FQDNs for `imap`/`pop3` used `example.com` domain for a third-party, changed to `gmail.com` as more familiar third-party/external MTA.
* Normalize config volume path
- Normalizing local config path references to `./docker-data/dms/config/`: `./config/`, `config/`, \``config`\`, `/etc/` (_volume mount src path prefix_).
- Normalize DMS volume paths to `docker-data/dms/mail-{data,state,log}`: `./mail`, `./mail-state` `./data/mail`, `./data/state`, `./data/logs`, `./data/maildata`, `./data/mailstate`, `./data/maillogs`, (_dropped/converted data volumes: `maildata`, `mailstate`_).
- Other docker images also adopt the `docker-data/{service name}/` prefix.
* `ssl.md` - Use `dms/custom-certs` where appropriate.
* Apply normalizations to README and example `docker-compose.yml`
---
Common terms, sometimes interchangeably used or now invalid depending on context: `mail`, `mail container`, `mail server`, `mail-server`, `mailserver`,`docker-mailserver`, `Docker Mailserver`.
Rough transformations applied to most matches (_conditionally, depending on context_):
- 'Docker Mailserver' => '`docker-mailserver`'
- 'mail container' => '`docker-mailserver`' (_optionally retaining ' container'_)
- 'mail server' => 'mail-server' / '`docker-mailserver`'
- 'mail-server' => '`docker-mailserver`'
- 'mailserver' => 'mail-server' / '`docker-mailserver`'
Additionally I checked `docker run` (_plus `exec`, `logs`, etc, sub-commands_) and `docker-compose` commands. Often finding usage of `mail` instead of the expected `mailserver`
Additionally changes `mailserver` hostname in k8s to `mail` to align with other non-k8s examples.
---
* drive-by revisions
Mostly minor revisions or improvements to docs that aren't related to normalization effort.
2021-09-22 23:29:37 +00:00
|
|
|
Provides the name of the 'docker-mailserver' image. The default value is
|
2021-10-16 09:27:17 +00:00
|
|
|
'${WHITE}${DEFAULT_IMAGE_NAME}${RESET}'
|
2021-09-19 14:47:08 +00:00
|
|
|
|
|
|
|
-c CONTAINER_NAME
|
|
|
|
Provides the name of the running container.
|
|
|
|
|
|
|
|
-p PATH
|
2021-09-21 06:51:59 +00:00
|
|
|
Provides the local path of the config folder to the temporary container instance.
|
docs(chore): Normalize for consistency (#2206)
"Brief" summary/overview of changes. See the PR discussion or individual commits from the PR for more details.
---
Only applies to the `docs/content/**` content (_and `setup` command_). `target/` and `test/` can be normalized at a later date.
* Normalize to `example.com`
- Domains normalized to `example.com`: `mywebserver.com`, `myserver.tld`, `domain.com`, `domain.tld`, `mydomain.net`, `my-domain.tld`, `my-domain.com`, `example.org`, `whoami.com`.
- Alternative domains normalized to `not-example.com`: `otherdomain.com`, `otherdomain.tld`, `domain2.tld`, `mybackupmx.com`, `whoareyou.org`.
- Email addresses normalized to `admin@example.com` (in `ssl.md`): `foo@bar.com`, `yourcurrentemail@gmail.com`, `email@email.com`, `admin@domain.tld`.
- Email addresses normalized to `external-account@gmail.com`: `bill@gates321boom.com`, `external@gmail.com`, `myemail@gmail.com`, `real-email-address@external-domain.com`.
- **`faq.md`:** A FAQ entry title with `sample.domain.com` changed to `subdomain.example.com`.
- **`mail-fetchmail.md`:** Config examples with FQDNs for `imap`/`pop3` used `example.com` domain for a third-party, changed to `gmail.com` as more familiar third-party/external MTA.
* Normalize config volume path
- Normalizing local config path references to `./docker-data/dms/config/`: `./config/`, `config/`, \``config`\`, `/etc/` (_volume mount src path prefix_).
- Normalize DMS volume paths to `docker-data/dms/mail-{data,state,log}`: `./mail`, `./mail-state` `./data/mail`, `./data/state`, `./data/logs`, `./data/maildata`, `./data/mailstate`, `./data/maillogs`, (_dropped/converted data volumes: `maildata`, `mailstate`_).
- Other docker images also adopt the `docker-data/{service name}/` prefix.
* `ssl.md` - Use `dms/custom-certs` where appropriate.
* Apply normalizations to README and example `docker-compose.yml`
---
Common terms, sometimes interchangeably used or now invalid depending on context: `mail`, `mail container`, `mail server`, `mail-server`, `mailserver`,`docker-mailserver`, `Docker Mailserver`.
Rough transformations applied to most matches (_conditionally, depending on context_):
- 'Docker Mailserver' => '`docker-mailserver`'
- 'mail container' => '`docker-mailserver`' (_optionally retaining ' container'_)
- 'mail server' => 'mail-server' / '`docker-mailserver`'
- 'mail-server' => '`docker-mailserver`'
- 'mailserver' => 'mail-server' / '`docker-mailserver`'
Additionally I checked `docker run` (_plus `exec`, `logs`, etc, sub-commands_) and `docker-compose` commands. Often finding usage of `mail` instead of the expected `mailserver`
Additionally changes `mailserver` hostname in k8s to `mail` to align with other non-k8s examples.
---
* drive-by revisions
Mostly minor revisions or improvements to docs that aren't related to normalization effort.
2021-09-22 23:29:37 +00:00
|
|
|
Does not work if an existing a 'docker-mailserver' container is already running.
|
2021-09-19 14:47:08 +00:00
|
|
|
|
|
|
|
${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.
|
|
|
|
|
2021-09-21 06:51:59 +00:00
|
|
|
${LBLUE}Podman${RESET}
|
|
|
|
-R
|
|
|
|
Accept running in Podman rootless mode. Ignored when using Docker / Docker Compose.
|
|
|
|
|
|
|
|
"
|
|
|
|
|
|
|
|
[[ ${1:-} == 'no-exit' ]] && return 0
|
|
|
|
|
|
|
|
# shellcheck disable=SC2059
|
2022-05-05 15:48:21 +00:00
|
|
|
printf '%s' "${ORANGE}EXIT STATUS${RESET}
|
2021-09-19 14:47:08 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
"
|
2019-11-22 14:42:25 +00:00
|
|
|
}
|
2019-11-22 15:10:42 +00:00
|
|
|
|
2023-05-25 23:01:41 +00:00
|
|
|
function _get_absolute_script_directory() {
|
2023-05-24 07:06:59 +00:00
|
|
|
if dirname "$(readlink -f "${0}")" &>/dev/null; then
|
2022-05-05 08:28:38 +00:00
|
|
|
DIR=$(dirname "$(readlink -f "${0}")")
|
2023-05-24 07:06:59 +00:00
|
|
|
elif realpath -e -L "${0}" &>/dev/null; then
|
2022-05-05 08:28:38 +00:00
|
|
|
DIR=$(realpath -e -L "${0}")
|
2021-04-07 09:11:54 +00:00
|
|
|
DIR="${DIR%/setup.sh}"
|
2020-09-06 10:27:40 +00:00
|
|
|
fi
|
2021-10-16 09:27:17 +00:00
|
|
|
}
|
2020-09-04 06:42:12 +00:00
|
|
|
|
2023-05-25 23:01:41 +00:00
|
|
|
function _set_default_config_path() {
|
2023-05-24 07:06:59 +00:00
|
|
|
if [[ -d "${DIR}/config" ]]; then
|
2021-10-16 09:27:17 +00:00
|
|
|
# legacy path (pre v10.2.0)
|
|
|
|
DEFAULT_CONFIG_PATH="${DIR}/config"
|
|
|
|
else
|
|
|
|
DEFAULT_CONFIG_PATH="${DIR}/docker-data/dms/config"
|
|
|
|
fi
|
2020-09-04 06:42:12 +00:00
|
|
|
}
|
2018-04-28 08:27:42 +00:00
|
|
|
|
2023-05-25 23:01:41 +00:00
|
|
|
function _handle_config_path() {
|
2023-05-24 07:06:59 +00:00
|
|
|
if [[ -z ${DESIRED_CONFIG_PATH} ]]; then
|
2021-09-21 06:51:59 +00:00
|
|
|
# no desired config path
|
2023-05-24 07:06:59 +00:00
|
|
|
if [[ -n ${CONTAINER_NAME} ]]; then
|
2021-09-21 06:51:59 +00:00
|
|
|
VOLUME=$(${CRI} inspect "${CONTAINER_NAME}" \
|
|
|
|
--format="{{range .Mounts}}{{ println .Source .Destination}}{{end}}" | \
|
|
|
|
grep "${DMS_CONFIG}$" 2>/dev/null || :)
|
|
|
|
fi
|
2018-04-28 08:27:42 +00:00
|
|
|
|
2023-05-24 07:06:59 +00:00
|
|
|
if [[ -n ${VOLUME} ]]; then
|
2021-09-21 06:51:59 +00:00
|
|
|
CONFIG_PATH=$(echo "${VOLUME}" | awk '{print $1}')
|
|
|
|
fi
|
2016-08-28 19:10:25 +00:00
|
|
|
|
2023-05-24 07:06:59 +00:00
|
|
|
if [[ -z ${CONFIG_PATH} ]]; then
|
2021-09-21 06:51:59 +00:00
|
|
|
CONFIG_PATH=${DEFAULT_CONFIG_PATH}
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
CONFIG_PATH=${DESIRED_CONFIG_PATH}
|
|
|
|
fi
|
2016-09-01 10:10:23 +00:00
|
|
|
}
|
|
|
|
|
2023-05-25 23:01:41 +00:00
|
|
|
function _run_in_new_container() {
|
2021-09-06 10:13:12 +00:00
|
|
|
# start temporary container with specified image
|
2023-05-24 07:06:59 +00:00
|
|
|
if ! ${CRI} history -q "${IMAGE_NAME}" &>/dev/null; then
|
2021-09-06 10:13:12 +00:00
|
|
|
echo "Image '${IMAGE_NAME}' not found. Pulling ..."
|
|
|
|
${CRI} pull "${IMAGE_NAME}"
|
2019-07-28 12:33:52 +00:00
|
|
|
fi
|
2021-09-06 10:13:12 +00:00
|
|
|
|
2021-09-19 14:47:08 +00:00
|
|
|
${CRI} run --rm "${USE_TTY}" \
|
2021-09-21 06:51:59 +00:00
|
|
|
-v "${CONFIG_PATH}:${DMS_CONFIG}${USE_SELINUX}" \
|
2022-03-08 23:30:29 +00:00
|
|
|
"${IMAGE_NAME}" "${@}"
|
2016-08-28 19:10:25 +00:00
|
|
|
}
|
|
|
|
|
2023-05-25 23:01:41 +00:00
|
|
|
function _main() {
|
2021-09-21 06:51:59 +00:00
|
|
|
_get_absolute_script_directory
|
2021-10-16 09:27:17 +00:00
|
|
|
_set_default_config_path
|
2021-09-21 06:51:59 +00:00
|
|
|
|
|
|
|
local OPTIND
|
2023-05-25 23:39:39 +00:00
|
|
|
while getopts ":c:i:p:zZR" OPT; do
|
2021-09-21 06:51:59 +00:00
|
|
|
case ${OPT} in
|
|
|
|
( i ) IMAGE_NAME="${OPTARG}" ;;
|
|
|
|
( z | Z ) USE_SELINUX=":${OPT}" ;;
|
|
|
|
( c ) CONTAINER_NAME="${OPTARG}" ;;
|
|
|
|
( R ) PODMAN_ROOTLESS=true ;;
|
|
|
|
( p )
|
|
|
|
case "${OPTARG}" in
|
|
|
|
( /* ) DESIRED_CONFIG_PATH="${OPTARG}" ;;
|
|
|
|
( * ) DESIRED_CONFIG_PATH="${DIR}/${OPTARG}" ;;
|
|
|
|
esac
|
|
|
|
|
2023-05-24 07:06:59 +00:00
|
|
|
if [[ ! -d ${DESIRED_CONFIG_PATH} ]]; then
|
2021-09-21 06:51:59 +00:00
|
|
|
echo "Specified directory '${DESIRED_CONFIG_PATH}' doesn't exist" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
( * )
|
|
|
|
echo "Invalid option: '-${OPTARG}'" >&2
|
|
|
|
echo -e "Use './setup.sh help' to get a complete overview.\n" >&2
|
|
|
|
_show_local_usage 'no-exit'
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
|
2023-05-24 07:06:59 +00:00
|
|
|
if command -v docker &>/dev/null; then
|
2020-09-04 06:42:12 +00:00
|
|
|
CRI=docker
|
2023-05-24 07:06:59 +00:00
|
|
|
elif command -v podman &>/dev/null; then
|
2020-09-04 06:42:12 +00:00
|
|
|
CRI=podman
|
2023-05-24 07:06:59 +00:00
|
|
|
if ! ${PODMAN_ROOTLESS} && [[ ${EUID} -ne 0 ]]; then
|
2021-09-21 06:51:59 +00:00
|
|
|
read -r -p "You are running Podman in rootless mode. Continue? [Y/n] "
|
|
|
|
[[ -n ${REPLY} ]] && [[ ${REPLY} =~ (n|N) ]] && exit 0
|
|
|
|
fi
|
2020-09-04 06:42:12 +00:00
|
|
|
else
|
2021-09-21 06:51:59 +00:00
|
|
|
echo 'No supported Container Runtime Interface detected.'
|
2021-09-19 14:47:08 +00:00
|
|
|
exit 1
|
2018-04-28 08:27:42 +00:00
|
|
|
fi
|
|
|
|
|
2021-01-16 09:16:05 +00:00
|
|
|
INFO=$(${CRI} ps --no-trunc --format "{{.Image}};{{.Names}}" --filter \
|
|
|
|
label=org.opencontainers.image.title="docker-mailserver" | tail -1)
|
2020-09-04 06:42:12 +00:00
|
|
|
|
2022-06-06 09:18:37 +00:00
|
|
|
[[ -z ${CONTAINER_NAME} ]] && CONTAINER_NAME=${INFO#*;}
|
2021-09-21 06:51:59 +00:00
|
|
|
[[ -z ${IMAGE_NAME} ]] && IMAGE_NAME=${INFO%;*}
|
2023-05-24 07:06:59 +00:00
|
|
|
if [[ -z ${IMAGE_NAME} ]]; then
|
2021-10-16 09:27:17 +00:00
|
|
|
IMAGE_NAME=${NAME:-${DEFAULT_IMAGE_NAME}}
|
2020-09-04 06:42:12 +00:00
|
|
|
fi
|
2016-09-01 10:10:23 +00:00
|
|
|
|
2023-05-24 07:06:59 +00:00
|
|
|
if test -t 0; then
|
docs(chore): Normalize for consistency (#2206)
"Brief" summary/overview of changes. See the PR discussion or individual commits from the PR for more details.
---
Only applies to the `docs/content/**` content (_and `setup` command_). `target/` and `test/` can be normalized at a later date.
* Normalize to `example.com`
- Domains normalized to `example.com`: `mywebserver.com`, `myserver.tld`, `domain.com`, `domain.tld`, `mydomain.net`, `my-domain.tld`, `my-domain.com`, `example.org`, `whoami.com`.
- Alternative domains normalized to `not-example.com`: `otherdomain.com`, `otherdomain.tld`, `domain2.tld`, `mybackupmx.com`, `whoareyou.org`.
- Email addresses normalized to `admin@example.com` (in `ssl.md`): `foo@bar.com`, `yourcurrentemail@gmail.com`, `email@email.com`, `admin@domain.tld`.
- Email addresses normalized to `external-account@gmail.com`: `bill@gates321boom.com`, `external@gmail.com`, `myemail@gmail.com`, `real-email-address@external-domain.com`.
- **`faq.md`:** A FAQ entry title with `sample.domain.com` changed to `subdomain.example.com`.
- **`mail-fetchmail.md`:** Config examples with FQDNs for `imap`/`pop3` used `example.com` domain for a third-party, changed to `gmail.com` as more familiar third-party/external MTA.
* Normalize config volume path
- Normalizing local config path references to `./docker-data/dms/config/`: `./config/`, `config/`, \``config`\`, `/etc/` (_volume mount src path prefix_).
- Normalize DMS volume paths to `docker-data/dms/mail-{data,state,log}`: `./mail`, `./mail-state` `./data/mail`, `./data/state`, `./data/logs`, `./data/maildata`, `./data/mailstate`, `./data/maillogs`, (_dropped/converted data volumes: `maildata`, `mailstate`_).
- Other docker images also adopt the `docker-data/{service name}/` prefix.
* `ssl.md` - Use `dms/custom-certs` where appropriate.
* Apply normalizations to README and example `docker-compose.yml`
---
Common terms, sometimes interchangeably used or now invalid depending on context: `mail`, `mail container`, `mail server`, `mail-server`, `mailserver`,`docker-mailserver`, `Docker Mailserver`.
Rough transformations applied to most matches (_conditionally, depending on context_):
- 'Docker Mailserver' => '`docker-mailserver`'
- 'mail container' => '`docker-mailserver`' (_optionally retaining ' container'_)
- 'mail server' => 'mail-server' / '`docker-mailserver`'
- 'mail-server' => '`docker-mailserver`'
- 'mailserver' => 'mail-server' / '`docker-mailserver`'
Additionally I checked `docker run` (_plus `exec`, `logs`, etc, sub-commands_) and `docker-compose` commands. Often finding usage of `mail` instead of the expected `mailserver`
Additionally changes `mailserver` hostname in k8s to `mail` to align with other non-k8s examples.
---
* drive-by revisions
Mostly minor revisions or improvements to docs that aren't related to normalization effort.
2021-09-22 23:29:37 +00:00
|
|
|
USE_TTY="-it"
|
2021-01-16 09:16:05 +00:00
|
|
|
else
|
|
|
|
# GitHub Actions will fail (or really anything else
|
|
|
|
# lacking an interactive tty) if we don't set a
|
|
|
|
# value here; "-t" alone works for these cases.
|
|
|
|
USE_TTY="-t"
|
2020-09-04 06:42:12 +00:00
|
|
|
fi
|
2016-08-28 19:10:25 +00:00
|
|
|
|
2021-09-21 06:51:59 +00:00
|
|
|
_handle_config_path
|
2016-08-28 19:10:25 +00:00
|
|
|
|
2023-05-24 07:06:59 +00:00
|
|
|
if [[ -n ${CONTAINER_NAME} ]]; then
|
2022-03-08 23:30:29 +00:00
|
|
|
${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" setup "${@}"
|
2020-09-04 06:42:12 +00:00
|
|
|
else
|
2022-03-08 23:30:29 +00:00
|
|
|
_run_in_new_container setup "${@}"
|
2020-09-04 06:42:12 +00:00
|
|
|
fi
|
|
|
|
|
2022-05-05 15:48:21 +00:00
|
|
|
[[ ${1:-} == 'help' ]] && _show_local_usage
|
2020-09-04 06:42:12 +00:00
|
|
|
|
2021-09-19 14:47:08 +00:00
|
|
|
return 0
|
2020-09-04 06:42:12 +00:00
|
|
|
}
|
2016-08-28 19:10:25 +00:00
|
|
|
|
2022-04-18 13:28:12 +00:00
|
|
|
[[ -z ${1:-} ]] && set 'help'
|
2022-03-08 23:30:29 +00:00
|
|
|
_main "${@}"
|