mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2024-11-26 02:57:04 +00:00
Added dialogs, so that the setup.sh can ask the user any questions even when its piped; Added additional email valdidation for the last step
This commit is contained in:
parent
6b52105b62
commit
980b83b124
@ -127,3 +127,28 @@ function ufw_allow {
|
|||||||
function restart_service {
|
function restart_service {
|
||||||
hide_output service $1 restart
|
hide_output service $1 restart
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## Dialog Functions ##
|
||||||
|
function message_box {
|
||||||
|
dialog --title "$1" --msgbox "$2" 0 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function input_box {
|
||||||
|
TMP=`mktemp`
|
||||||
|
dialog --title "$1" --inputbox "$2" 0 0 "$3" 2>$TMP
|
||||||
|
|
||||||
|
respose=$?
|
||||||
|
|
||||||
|
case $respose in
|
||||||
|
0)
|
||||||
|
result=$(<$TMP)
|
||||||
|
;;
|
||||||
|
1)
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
255)
|
||||||
|
exit
|
||||||
|
esac
|
||||||
|
|
||||||
|
rm $TMP
|
||||||
|
}
|
||||||
|
145
setup/start.sh
145
setup/start.sh
@ -38,12 +38,11 @@ fi
|
|||||||
|
|
||||||
if [ -t 0 ]; then
|
if [ -t 0 ]; then
|
||||||
# In an interactive shell...
|
# In an interactive shell...
|
||||||
echo
|
# Install dialog
|
||||||
echo "Hello and thanks for deploying a Mail-in-a-Box!"
|
echo "Preparing installation ... "
|
||||||
echo "-----------------------------------------------"
|
apt_install dialog
|
||||||
echo
|
message_box "Hello and thanks for deploying a Mail-in-a-Box!" \
|
||||||
echo "I'm going to ask you a few questions. To change your answers later,"
|
"I'm going to ask you a few questions. To change your answers later, just re-run this script."
|
||||||
echo "later, just re-run this script."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Recall the last settings used if we're running this a second time.
|
# Recall the last settings used if we're running this a second time.
|
||||||
@ -64,24 +63,26 @@ if [ -z "$PRIMARY_HOSTNAME" ]; then
|
|||||||
if [ -z "$DEFAULT_PRIMARY_HOSTNAME" ]; then
|
if [ -z "$DEFAULT_PRIMARY_HOSTNAME" ]; then
|
||||||
# This is the first run. Ask the user for his email address so we can
|
# This is the first run. Ask the user for his email address so we can
|
||||||
# provide the best default for the box's hostname.
|
# provide the best default for the box's hostname.
|
||||||
echo
|
input_box "What email address are you setting this box up to manage?" \
|
||||||
echo "What email address are you setting this box up to manage?"
|
"The part after the @-sign must be a domain name or subdomain
|
||||||
echo ""
|
\nthat you control. You can add other email addresses to this
|
||||||
echo "The part after the @-sign must be a domain name or subdomain"
|
\nbox later (including email addresses on other domain names
|
||||||
echo "that you control. You can add other email addresses to this"
|
\nor subdomains you control).\n
|
||||||
echo "box later (including email addresses on other domain names"
|
\nWe've guessed an email address. Backspace it and type in what
|
||||||
echo "or subdomains you control)."
|
\nyou really want.\n
|
||||||
echo
|
\nEmail Address (me@`get_default_hostname`): "
|
||||||
echo "We've guessed an email address. Backspace it and type in what"
|
|
||||||
echo "you really want."
|
if [ -z "$result" ]; then
|
||||||
echo
|
EMAIL_ADDR=me@`get_default_hostname`
|
||||||
read -e -i "me@`get_default_hostname`" -p "Email Address: " EMAIL_ADDR
|
else
|
||||||
|
EMAIL_ADDR=$result
|
||||||
|
fi
|
||||||
|
|
||||||
while ! management/mailconfig.py validate-email "$EMAIL_ADDR"
|
while ! management/mailconfig.py validate-email "$EMAIL_ADDR"
|
||||||
do
|
do
|
||||||
echo "That's not a valid email address."
|
input_box "What email address are you setting this box up to manage?" \
|
||||||
echo
|
"That's not a valid email address." $EMAIL_ADDR
|
||||||
read -e -i "$EMAIL_ADDR" -p "Email Address: " EMAIL_ADDR
|
EMAIL_ADDR=$result
|
||||||
done
|
done
|
||||||
|
|
||||||
# Take the part after the @-sign as the user's domain name, and add
|
# Take the part after the @-sign as the user's domain name, and add
|
||||||
@ -89,17 +90,19 @@ if [ -z "$PRIMARY_HOSTNAME" ]; then
|
|||||||
DEFAULT_PRIMARY_HOSTNAME=box.$(echo $EMAIL_ADDR | sed 's/.*@//')
|
DEFAULT_PRIMARY_HOSTNAME=box.$(echo $EMAIL_ADDR | sed 's/.*@//')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
input_box "Hostname" \
|
||||||
echo "This box needs a name, called a 'hostname'. The name will form a part"
|
"This box needs a name, called a 'hostname'. The name will form a part
|
||||||
echo "of the box's web address."
|
\nof the box's web address.\n
|
||||||
echo
|
\nWe recommend that the name be a subdomain of the domain in your email
|
||||||
echo "We recommend that the name be a subdomain of the domain in your email"
|
\naddress, so we're suggesting $DEFAULT_PRIMARY_HOSTNAME.
|
||||||
echo "address, so we're suggesting $DEFAULT_PRIMARY_HOSTNAME."
|
\nYou can change it, but we recommend you don't.\n
|
||||||
echo
|
\nHostname ($DEFAULT_PRIMARY_HOSTNAME): "
|
||||||
echo "You can change it, but we recommend you don't."
|
|
||||||
echo
|
|
||||||
|
|
||||||
read -e -i "$DEFAULT_PRIMARY_HOSTNAME" -p "Hostname: " PRIMARY_HOSTNAME
|
if [ -z "$result" ]; then
|
||||||
|
PRIMARY_HOSTNAME=$DEFAULT_PRIMARY_HOSTNAME
|
||||||
|
else
|
||||||
|
PRIMARY_HOSTNAME=$result
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If the machine is behind a NAT, inside a VM, etc., it may not know
|
# If the machine is behind a NAT, inside a VM, etc., it may not know
|
||||||
@ -125,11 +128,16 @@ if [ -z "$PUBLIC_IP" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$PUBLIC_IP" ]; then
|
if [ -z "$PUBLIC_IP" ]; then
|
||||||
echo
|
input_box "Your public IP address" \
|
||||||
echo "Enter the public IP address of this machine, as given to you by your ISP."
|
"Enter the public IP address of this machine,
|
||||||
echo
|
as given to you by your ISP.\n
|
||||||
|
\nPublic IP ($DEFAULT_PUBLIC_IP): "
|
||||||
|
|
||||||
read -e -i "$DEFAULT_PUBLIC_IP" -p "Public IP: " PUBLIC_IP
|
if [ -z "$result" ]; then
|
||||||
|
PUBLIC_IP=$DEFAULT_PUBLIC_IP
|
||||||
|
else
|
||||||
|
PUBLIC_IP=$result
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -151,13 +159,16 @@ if [ -z "$PUBLIC_IPV6" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$PUBLIC_IPV6" && $MATCHED == 0 ]]; then
|
if [[ -z "$PUBLIC_IPV6" && $MATCHED == 0 ]]; then
|
||||||
echo
|
input_box "IPv6 Optional" \
|
||||||
echo "Optional:"
|
"Enter the public IPv6 address of this machine, as given to you by your ISP.
|
||||||
echo "Enter the public IPv6 address of this machine, as given to you by your ISP."
|
\nLeave blank if the machine does not have an IPv6 address.\n
|
||||||
echo "Leave blank if the machine does not have an IPv6 address."
|
\nPublic IPv6 ($DEFAULT_PUBLIC_IPV6): "
|
||||||
echo
|
|
||||||
|
|
||||||
read -e -i "$DEFAULT_PUBLIC_IPV6" -p "Public IPv6: " PUBLIC_IPV6
|
if [ -z "$result" ]; then
|
||||||
|
PUBLIC_IPV6=$DEFAULT_PUBLIC_IPV6
|
||||||
|
else
|
||||||
|
PUBLIC_IPV6=$result
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -171,13 +182,11 @@ if [ -z "$PRIVATE_IPV6" ]; then
|
|||||||
PRIVATE_IPV6=$(get_default_privateip 6)
|
PRIVATE_IPV6=$(get_default_privateip 6)
|
||||||
fi
|
fi
|
||||||
if [[ -z "$PRIVATE_IP" && -z "$PRIVATE_IPV6" ]]; then
|
if [[ -z "$PRIVATE_IP" && -z "$PRIVATE_IPV6" ]]; then
|
||||||
echo
|
message_box "Error" \
|
||||||
echo "I could not determine the IP or IPv6 address of the network inteface"
|
"I could not determine the IP or IPv6 address of the network inteface
|
||||||
echo "for connecting to the Internet. Setup must stop."
|
\nfor connecting to the Internet. Setup must stop.\n
|
||||||
echo
|
`hostname -I`\n
|
||||||
hostname -I
|
`route`"
|
||||||
route
|
|
||||||
echo
|
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -190,19 +199,25 @@ fi
|
|||||||
if [ ! -z "$DEFAULT_STORAGE_ROOT" ] && [ ! -z "$DEFAULT_CSR_COUNTRY" ] && [ -f $DEFAULT_STORAGE_ROOT/ssl/ssl_cert_sign_req.csr ]; then
|
if [ ! -z "$DEFAULT_STORAGE_ROOT" ] && [ ! -z "$DEFAULT_CSR_COUNTRY" ] && [ -f $DEFAULT_STORAGE_ROOT/ssl/ssl_cert_sign_req.csr ]; then
|
||||||
CSR_COUNTRY=$DEFAULT_CSR_COUNTRY
|
CSR_COUNTRY=$DEFAULT_CSR_COUNTRY
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$CSR_COUNTRY" ]; then
|
if [ -z "$CSR_COUNTRY" ]; then
|
||||||
echo
|
input_box "Country Code" \
|
||||||
echo "Enter the two-letter, uppercase country code for where you"
|
"Enter the two-letter, uppercase country code for where you
|
||||||
echo "live or where your organization is based. (This is used to"
|
\nlive or where your organization is based. (This is used to
|
||||||
echo "create an SSL certificate.)"
|
\ncreate an SSL certificate.)\n
|
||||||
echo
|
\nCountry Code ($DEFAULT_CSR_COUNTRY): "
|
||||||
|
|
||||||
|
if [ -z "$result" ]; then
|
||||||
|
CSR_COUNTRY=$DEFAULT_CSR_COUNTRY
|
||||||
|
else
|
||||||
|
CSR_COUNTRY=$result
|
||||||
|
fi
|
||||||
|
|
||||||
#if [ -z "$DEFAULT_CSR_COUNTRY" ]; then
|
#if [ -z "$DEFAULT_CSR_COUNTRY" ]; then
|
||||||
# # set a default on first run
|
# # set a default on first run
|
||||||
# DEFAULT_CSR_COUNTRY=...?
|
# DEFAULT_CSR_COUNTRY=...?
|
||||||
#fi
|
#fi
|
||||||
|
|
||||||
read -e -i "$DEFAULT_CSR_COUNTRY" -p "Country Code: " CSR_COUNTRY
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Automatic configuration, e.g. as used in our Vagrant configuration.
|
# Automatic configuration, e.g. as used in our Vagrant configuration.
|
||||||
@ -292,12 +307,24 @@ if [ -z "`tools/mail.py user`" ]; then
|
|||||||
if [ -z "$EMAIL_ADDR" ]; then
|
if [ -z "$EMAIL_ADDR" ]; then
|
||||||
# In an interactive shell, ask the user for an email address.
|
# In an interactive shell, ask the user for an email address.
|
||||||
if [ -t 0 ]; then
|
if [ -t 0 ]; then
|
||||||
echo
|
input_box "Create your first mail user" \
|
||||||
echo "Let's create your first mail user."
|
"Let's create your first mail user.\n
|
||||||
read -e -i "user@$PRIMARY_HOSTNAME" -p "Email Address: " EMAIL_ADDR
|
\nEmail Address (user@$PRIMARY_HOSTNAME): "
|
||||||
|
|
||||||
# But in a non-interactive shell, just make something up. This
|
if [ -z "$result" ]; then
|
||||||
# is normally for testing.
|
EMAIL_ADDR=me@`get_default_hostname`
|
||||||
|
else
|
||||||
|
EMAIL_ADDR=$result
|
||||||
|
fi
|
||||||
|
|
||||||
|
while ! management/mailconfig.py validate-email "$EMAIL_ADDR"
|
||||||
|
do
|
||||||
|
input_box "What email address are you setting this box up to manage?"\
|
||||||
|
"That's not a valid email address." $EMAIL_ADDR
|
||||||
|
EMAIL_ADDR=$result
|
||||||
|
done
|
||||||
|
# But in a non-interactive shell, just make something up.
|
||||||
|
# This is normally for testing.
|
||||||
else
|
else
|
||||||
# Use me@PRIMARY_HOSTNAME
|
# Use me@PRIMARY_HOSTNAME
|
||||||
EMAIL_ADDR=me@$PRIMARY_HOSTNAME
|
EMAIL_ADDR=me@$PRIMARY_HOSTNAME
|
||||||
|
Loading…
Reference in New Issue
Block a user