2014-08-25 12:09:37 +00:00
|
|
|
# If there aren't any mail users yet, create one.
|
2021-05-03 23:28:23 +00:00
|
|
|
if [ -z "$(management/cli.py user)" ]; then
|
2020-10-29 19:10:11 +00:00
|
|
|
# The outut of "management/cli.py user" is a list of mail users. If there
|
2014-08-25 12:09:37 +00:00
|
|
|
# aren't any yet, it'll be empty.
|
|
|
|
|
|
|
|
# If we didn't ask for an email address at the start, do so now.
|
2018-12-14 01:30:05 +00:00
|
|
|
if [ -z "${EMAIL_ADDR:-}" ]; then
|
2014-08-25 12:09:37 +00:00
|
|
|
# In an interactive shell, ask the user for an email address.
|
2018-11-30 15:24:19 +00:00
|
|
|
if [ -z "${NONINTERACTIVE:-}" ]; then
|
2014-08-25 12:09:37 +00:00
|
|
|
input_box "Mail Account" \
|
|
|
|
"Let's create your first mail account.
|
|
|
|
\n\nWhat email address do you want?" \
|
2021-05-03 23:28:23 +00:00
|
|
|
me@$(get_default_hostname) \
|
2014-08-25 12:09:37 +00:00
|
|
|
EMAIL_ADDR
|
|
|
|
|
|
|
|
if [ -z "$EMAIL_ADDR" ]; then
|
|
|
|
# user hit ESC/cancel
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
while ! management/mailconfig.py validate-email "$EMAIL_ADDR"
|
|
|
|
do
|
|
|
|
input_box "Mail Account" \
|
|
|
|
"That's not a valid email address.
|
|
|
|
\n\nWhat email address do you want?" \
|
|
|
|
$EMAIL_ADDR \
|
|
|
|
EMAIL_ADDR
|
|
|
|
if [ -z "$EMAIL_ADDR" ]; then
|
|
|
|
# user hit ESC/cancel
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# But in a non-interactive shell, just make something up.
|
|
|
|
# This is normally for testing.
|
|
|
|
else
|
|
|
|
# Use me@PRIMARY_HOSTNAME
|
|
|
|
EMAIL_ADDR=me@$PRIMARY_HOSTNAME
|
2017-03-26 17:23:34 +00:00
|
|
|
EMAIL_PW=12345678
|
2014-08-25 12:09:37 +00:00
|
|
|
echo
|
|
|
|
echo "Creating a new administrative mail account for $EMAIL_ADDR with password $EMAIL_PW."
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "Okay. I'm about to set up $EMAIL_ADDR for you. This account will also"
|
|
|
|
echo "have access to the box's control panel."
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create the user's mail account. This will ask for a password if none was given above.
|
2020-10-29 19:10:11 +00:00
|
|
|
management/cli.py user add $EMAIL_ADDR ${EMAIL_PW:-}
|
2014-08-25 12:09:37 +00:00
|
|
|
|
|
|
|
# Make it an admin.
|
2020-10-29 19:10:11 +00:00
|
|
|
hide_output management/cli.py user make-admin $EMAIL_ADDR
|
2014-08-25 12:09:37 +00:00
|
|
|
|
|
|
|
# Create an alias to which we'll direct all automatically-created administrative aliases.
|
2020-10-29 19:10:11 +00:00
|
|
|
management/cli.py alias add administrator@$PRIMARY_HOSTNAME $EMAIL_ADDR > /dev/null
|
2017-03-26 17:23:34 +00:00
|
|
|
fi
|