2022-10-17 08:40:09 +00:00
|
|
|
#!/bin/bash
|
2021-09-11 23:29:02 +00:00
|
|
|
|
|
|
|
set -euE -o pipefail
|
|
|
|
|
2022-05-10 15:50:33 +00:00
|
|
|
# shellcheck source=../scripts/helpers/index.sh
|
|
|
|
source /usr/local/bin/helpers/index.sh
|
|
|
|
|
2021-09-11 23:29:02 +00:00
|
|
|
function _usage
|
|
|
|
{
|
|
|
|
# shellcheck disable=SC2059
|
2022-05-10 15:50:33 +00:00
|
|
|
printf '%s' "${PURPLE}SETUP${RED}(${YELLOW}1${RED})
|
2021-09-11 23:29:02 +00:00
|
|
|
|
|
|
|
${ORANGE}NAME${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
setup - 'docker-mailserver' Administration & Configuration CLI
|
2021-09-11 23:29:02 +00:00
|
|
|
|
|
|
|
${ORANGE}SYNOPSIS${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
setup [ OPTIONS${RED}...${RESET} ] COMMAND [ help ${RED}|${RESET} ARGUMENTS${RED}...${RESET} ]
|
2021-09-11 23:29:02 +00:00
|
|
|
|
2022-05-07 22:28:32 +00:00
|
|
|
COMMAND ${RED}:=${RESET} { email ${RED}|${RESET} alias ${RED}|${RESET} quota ${RED}|${RESET} dovecot-master ${RED}|${RESET} config ${RED}|${RESET} relay ${RED}|${RESET} debug } SUBCOMMAND
|
2021-09-11 23:29:02 +00:00
|
|
|
|
|
|
|
${ORANGE}DESCRIPTION${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
This is the main administration command that you use for all your interactions with
|
|
|
|
'docker-mailserver'. Initial setup, configuration, and much more is done with this CLI tool.
|
2021-09-11 23:29:02 +00:00
|
|
|
|
2023-04-10 09:37:25 +00:00
|
|
|
Most subcommands can provide additional information and examples by appending 'help'.
|
|
|
|
For example: 'setup email add help'
|
2021-09-11 23:29:02 +00:00
|
|
|
|
|
|
|
${RED}[${ORANGE}SUB${RED}]${ORANGE}COMMANDS${RESET}
|
|
|
|
${LBLUE}COMMAND${RESET} email ${RED}:=${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
setup email ${CYAN}add${RESET} <EMAIL ADDRESS> [<PASSWORD>]
|
|
|
|
setup email ${CYAN}update${RESET} <EMAIL ADDRESS> [<PASSWORD>]
|
|
|
|
setup email ${CYAN}del${RESET} [ OPTIONS${RED}...${RESET} ] <EMAIL ADDRESS> [ <EMAIL ADDRESS>${RED}...${RESET} ]
|
|
|
|
setup email ${CYAN}restrict${RESET} <add${RED}|${RESET}del${RED}|${RESET}list> <send${RED}|${RESET}receive> [<EMAIL ADDRESS>]
|
|
|
|
setup email ${CYAN}list${RESET}
|
2021-09-11 23:29:02 +00:00
|
|
|
|
|
|
|
${LBLUE}COMMAND${RESET} alias ${RED}:=${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
setup alias ${CYAN}add${RESET} <EMAIL ADDRESS> <RECIPIENT>
|
|
|
|
setup alias ${CYAN}del${RESET} <EMAIL ADDRESS> <RECIPIENT>
|
|
|
|
setup alias ${CYAN}list${RESET}
|
2021-09-11 23:29:02 +00:00
|
|
|
|
|
|
|
${LBLUE}COMMAND${RESET} quota ${RED}:=${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
setup quota ${CYAN}set${RESET} <EMAIL ADDRESS> [<QUOTA>]
|
|
|
|
setup quota ${CYAN}del${RESET} <EMAIL ADDRESS>
|
2021-09-11 23:29:02 +00:00
|
|
|
|
2022-05-07 22:28:32 +00:00
|
|
|
${LBLUE}COMMAND${RESET} dovecot-master ${RED}:=${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
setup dovecot-master ${CYAN}add${RESET} <USERNAME> [<PASSWORD>]
|
|
|
|
setup dovecot-master ${CYAN}update${RESET} <USERNAME> [<PASSWORD>]
|
|
|
|
setup dovecot-master ${CYAN}del${RESET} [ OPTIONS${RED}...${RESET} ] <USERNAME> [ <USERNAME>${RED}...${RESET} ]
|
|
|
|
setup dovecot-master ${CYAN}list${RESET}
|
2022-05-07 22:28:32 +00:00
|
|
|
|
2021-09-11 23:29:02 +00:00
|
|
|
${LBLUE}COMMAND${RESET} config ${RED}:=${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
setup config ${CYAN}dkim${RESET} [ ARGUMENTS${RED}...${RESET} ]
|
2021-09-11 23:29:02 +00:00
|
|
|
|
|
|
|
${LBLUE}COMMAND${RESET} relay ${RED}:=${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
setup relay ${CYAN}add-auth${RESET} <DOMAIN> <USERNAME> [<PASSWORD>]
|
|
|
|
setup relay ${CYAN}add-domain${RESET} <DOMAIN> <HOST> [<PORT>]
|
|
|
|
setup relay ${CYAN}exclude-domain${RESET} <DOMAIN>
|
2021-09-11 23:29:02 +00:00
|
|
|
|
2022-04-19 08:44:51 +00:00
|
|
|
${LBLUE}COMMAND${RESET} fail2ban ${RED}:=${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
setup fail2ban ${RESET}
|
|
|
|
setup fail2ban ${CYAN}ban${RESET} <IP>
|
|
|
|
setup fail2ban ${CYAN}unban${RESET} <IP>
|
2022-04-19 08:44:51 +00:00
|
|
|
|
2021-09-11 23:29:02 +00:00
|
|
|
${LBLUE}COMMAND${RESET} debug ${RED}:=${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
setup debug ${CYAN}fetchmail${RESET}
|
|
|
|
setup debug ${CYAN}login${RESET} <COMMANDS>
|
|
|
|
setup debug ${CYAN}show-mail-logs${RESET}
|
2021-09-11 23:29:02 +00:00
|
|
|
|
|
|
|
${ORANGE}EXAMPLES${RESET}
|
2023-04-10 09:37:25 +00:00
|
|
|
${LWHITE}setup email add test@example.com${RESET}
|
2022-05-10 15:50:33 +00:00
|
|
|
Add the email account ${LWHITE}test@example.com${RESET}. You will be prompted
|
2021-09-11 23:29:02 +00:00
|
|
|
to input a password afterwards since no password was supplied.
|
|
|
|
|
2023-04-10 09:37:25 +00:00
|
|
|
${LWHITE}setup config dkim keysize 2048 domain 'example.com,not-example.com'${RESET}
|
|
|
|
Creates keys of length 2048 for the domains in comma-seperated list.
|
|
|
|
This is necessary when using LDAP as the required domains cannot be inferred.
|
2021-09-11 23:29:02 +00:00
|
|
|
|
2023-04-10 09:37:25 +00:00
|
|
|
${LWHITE}setup config dkim help${RESET}
|
2022-05-10 15:50:33 +00:00
|
|
|
This will provide you with a detailed explanation on how to use the ${LWHITE}
|
2021-09-11 23:29:02 +00:00
|
|
|
config dkim${RESET} command, showing what arguments can be passed and what they do.
|
|
|
|
|
|
|
|
"
|
|
|
|
}
|
|
|
|
function _invalid_command
|
|
|
|
{
|
|
|
|
echo "The command '${*}' is invalid.
|
2023-04-10 09:37:25 +00:00
|
|
|
Use \`setup help\` to get an overview of all commands." >&2
|
2021-09-11 23:29:02 +00:00
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
function _main
|
|
|
|
{
|
|
|
|
case ${1:-} in
|
|
|
|
|
2021-09-19 14:47:08 +00:00
|
|
|
( email )
|
2021-09-11 23:29:02 +00:00
|
|
|
case ${2:-} in
|
2021-09-19 14:47:08 +00:00
|
|
|
( add ) shift 2 ; addmailuser "${@}" ;;
|
|
|
|
( update ) shift 2 ; updatemailuser "${@}" ;;
|
|
|
|
( del ) shift 2 ; delmailuser "${@}" ;;
|
|
|
|
( restrict ) shift 2 ; restrict-access "${@}" ;;
|
|
|
|
( list ) listmailuser ;;
|
2022-10-23 10:57:07 +00:00
|
|
|
( * ) _invalid_command "${@}" ;;
|
2021-09-11 23:29:02 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
2021-09-19 14:47:08 +00:00
|
|
|
( alias )
|
2021-09-11 23:29:02 +00:00
|
|
|
case ${2:-} in
|
2022-10-23 10:57:07 +00:00
|
|
|
( add ) shift 2 ; addalias "${@}" ;;
|
|
|
|
( del ) shift 2 ; delalias "${@}" ;;
|
2021-09-19 14:47:08 +00:00
|
|
|
( list ) shift 2 ; listalias ;;
|
2022-10-23 10:57:07 +00:00
|
|
|
( * ) _invalid_command "${@}" ;;
|
2021-09-11 23:29:02 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
2021-09-19 14:47:08 +00:00
|
|
|
( quota )
|
2021-09-11 23:29:02 +00:00
|
|
|
case ${2:-} in
|
2021-09-19 14:47:08 +00:00
|
|
|
( set ) shift 2 ; setquota "${@}" ;;
|
|
|
|
( del ) shift 2 ; delquota "${@}" ;;
|
2022-10-23 10:57:07 +00:00
|
|
|
( * ) _invalid_command "${@}" ;;
|
2021-09-11 23:29:02 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
2022-05-07 22:28:32 +00:00
|
|
|
( dovecot-master )
|
|
|
|
case ${2:-} in
|
|
|
|
( add ) shift 2 ; adddovecotmasteruser "${@}" ;;
|
|
|
|
( update ) shift 2 ; updatedovecotmasteruser "${@}" ;;
|
|
|
|
( del ) shift 2 ; deldovecotmasteruser "${@}" ;;
|
|
|
|
( list ) listdovecotmasteruser ;;
|
2022-10-23 10:57:07 +00:00
|
|
|
( * ) _invalid_command "${@}" ;;
|
2022-05-07 22:28:32 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
2021-09-19 14:47:08 +00:00
|
|
|
( config )
|
2021-09-11 23:29:02 +00:00
|
|
|
case ${2:-} in
|
2021-09-19 14:47:08 +00:00
|
|
|
( dkim ) shift 2 ; open-dkim "${@}" ;;
|
2022-10-23 10:57:07 +00:00
|
|
|
( * ) _invalid_command "${@}" ;;
|
2021-09-11 23:29:02 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
2021-09-19 14:47:08 +00:00
|
|
|
( relay )
|
2021-09-11 23:29:02 +00:00
|
|
|
case ${2:-} in
|
2021-09-19 14:47:08 +00:00
|
|
|
( add-domain ) shift 2 ; addrelayhost "${@}" ;;
|
|
|
|
( add-auth ) shift 2 ; addsaslpassword "${@}" ;;
|
|
|
|
( exclude-domain ) shift 2 ; excluderelaydomain "${@}" ;;
|
2022-10-23 10:57:07 +00:00
|
|
|
( * ) _invalid_command "${@}" ;;
|
2021-09-11 23:29:02 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
2022-04-19 08:44:51 +00:00
|
|
|
( fail2ban ) shift 1 ; fail2ban "${@}" ;;
|
|
|
|
|
2021-09-19 14:47:08 +00:00
|
|
|
( debug )
|
2021-09-11 23:29:02 +00:00
|
|
|
case ${2:-} in
|
2021-09-19 14:47:08 +00:00
|
|
|
( fetchmail ) debug-fetchmail ;;
|
|
|
|
( show-mail-logs ) cat /var/log/mail/mail.log ;;
|
|
|
|
( login )
|
2021-09-11 23:29:02 +00:00
|
|
|
shift 2
|
|
|
|
if [[ -z ${1:-} ]]
|
|
|
|
then
|
|
|
|
/bin/bash
|
|
|
|
else
|
|
|
|
/bin/bash -c "${@}"
|
|
|
|
fi
|
|
|
|
;;
|
2021-09-19 14:47:08 +00:00
|
|
|
( * ) _invalid_command "${*}" ;;
|
2021-09-11 23:29:02 +00:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
|
2021-09-19 14:47:08 +00:00
|
|
|
( help ) _usage ;;
|
|
|
|
( * ) _invalid_command "${*}" ;;
|
2021-09-11 23:29:02 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2022-04-18 13:28:12 +00:00
|
|
|
if [[ -z ${1:-} ]]
|
|
|
|
then
|
|
|
|
_usage
|
|
|
|
else
|
|
|
|
_main "${@}"
|
|
|
|
fi
|