2018-11-30 15:24:19 +00:00
if [ -z " ${ NONINTERACTIVE :- } " ] ; then
2014-08-25 12:09:37 +00:00
# Install 'dialog' so we can ask the user questions. The original motivation for
# this was being able to ask the user for input even if stdin has been redirected,
# e.g. if we piped a bootstrapping install script to bash to get started. In that
# case, the nifty '[ -t 0 ]' test won't work. But with Vagrant we must suppress so we
2016-01-03 15:48:23 +00:00
# use a shell flag instead. Really suppress any output from installing dialog.
2015-05-03 14:44:37 +00:00
#
2016-01-03 15:48:23 +00:00
# Also install dependencies needed to validate the email address.
2015-06-10 13:43:22 +00:00
if [ ! -f /usr/bin/dialog ] || [ ! -f /usr/bin/python3 ] || [ ! -f /usr/bin/pip3 ] ; then
echo Installing packages needed for setup...
apt-get -q -q update
apt_get_quiet install dialog python3 python3-pip || exit 1
fi
2015-05-03 14:44:37 +00:00
2018-01-20 15:54:56 +00:00
# Installing email_validator is repeated in setup/management.sh, but in setup/management.sh
# we install it inside a virtualenv. In this script, we don't have the virtualenv yet
# so we install the python package globally.
2015-11-18 14:43:08 +00:00
hide_output pip3 install "email_validator>=1.0.0" || exit 1
2015-05-03 14:44:37 +00:00
2014-08-25 12:09:37 +00:00
message_box "Mail-in-a-Box Installation" \
" Hello and thanks for deploying a Mail-in-a-Box!
\n \n I' m going to ask you a few questions.
2016-02-14 18:40:43 +00:00
\n \n To change your answers later, just run 'sudo mailinabox' from the command line.
2016-02-14 19:24:00 +00:00
\n \n NOTE: You should only install this on a brand new Ubuntu installation 100% dedicated to Mail-in-a-Box. Mail-in-a-Box will, for example, remove apache2."
2014-08-25 12:09:37 +00:00
fi
# The box needs a name.
2018-11-30 15:24:19 +00:00
if [ -z " ${ PRIMARY_HOSTNAME :- } " ] ; then
if [ -z " ${ DEFAULT_PRIMARY_HOSTNAME :- } " ] ; then
2014-08-25 12:26:39 +00:00
# We recommend to use box.example.com as this hosts name. The
# domain the user possibly wants to use is example.com then.
# We strip the string "box." from the hostname to get the mail
# domain. If the hostname differs, nothing happens here.
DEFAULT_DOMAIN_GUESS = $( echo $( get_default_hostname) | sed -e 's/^box\.//' )
2014-08-25 12:09:37 +00:00
# This is the first run. Ask the user for his email address so we can
# provide the best default for the box's hostname.
input_box "Your Email Address" \
" What email address are you setting this box up to manage?
\n \n The part after the @-sign must be a domain name or subdomain
that you control. You can add other email addresses to this
box later ( including email addresses on other domain names
or subdomains you control) .
\n \n We' ve guessed an email address. Backspace it and type in what
you really want.
\n \n Email Address:" \
2014-08-25 12:26:39 +00:00
" me@ $DEFAULT_DOMAIN_GUESS " \
2014-08-25 12:09:37 +00:00
EMAIL_ADDR
if [ -z " $EMAIL_ADDR " ] ; then
# user hit ESC/cancel
exit
fi
2018-01-20 15:54:56 +00:00
while ! python3 management/mailconfig.py validate-email " $EMAIL_ADDR "
2014-08-25 12:09:37 +00:00
do
input_box "Your Email Address" \
"That's not a valid email address.\n\nWhat email address are you setting this box up to manage?" \
$EMAIL_ADDR \
EMAIL_ADDR
if [ -z " $EMAIL_ADDR " ] ; then
# user hit ESC/cancel
exit
fi
done
# Take the part after the @-sign as the user's domain name, and add
# 'box.' to the beginning to create a default hostname for this machine.
DEFAULT_PRIMARY_HOSTNAME = box.$( echo $EMAIL_ADDR | sed 's/.*@//' )
fi
input_box "Hostname" \
" This box needs a name, called a 'hostname'. The name will form a part of the box's web address.
\n \n We recommend that the name be a subdomain of the domain in your email
address, so we' re suggesting $DEFAULT_PRIMARY_HOSTNAME .
\n \n You can change it, but we recommend you don' t.
\n \n Hostname:" \
$DEFAULT_PRIMARY_HOSTNAME \
PRIMARY_HOSTNAME
2018-11-02 08:07:15 +00:00
# Regular expression to check if the hostname is of the form *.localdomain
2018-10-25 03:31:20 +00:00
RE = '^.+\.localdomain$'
2018-11-02 08:07:15 +00:00
# Regular expressions to check if the hostname is a valid FQDN
2018-10-25 03:31:20 +00:00
RE1 = '^.{4,253}$'
2019-07-27 08:03:15 +00:00
RE2 = '^((xn--)?[[:alnum:]][[:alnum:]\-]{0,61}[[:alnum:]]\.)+(xn--)?[a-zA-Z]{2,63}$'
2014-08-25 12:09:37 +00:00
if [ -z " $PRIMARY_HOSTNAME " ] ; then
# user hit ESC/cancel
2018-10-25 03:31:20 +00:00
exit 1
elif [ [ $PRIMARY_HOSTNAME = ~ $RE ] ] ; then
echo "Warning: Hostname cannot be *.localdomain."
elif ! [ [ $PRIMARY_HOSTNAME = ~ $RE1 && $PRIMARY_HOSTNAME = ~ $RE2 ] ] ; then
echo "Warning: Hostname is not a valid fully qualified domain name (FQDN)."
2014-08-25 12:09:37 +00:00
fi
fi
# If the machine is behind a NAT, inside a VM, etc., it may not know
# its IP address on the public network / the Internet. Ask the Internet
# and possibly confirm with user.
2018-11-30 15:24:19 +00:00
if [ -z " ${ PUBLIC_IP :- } " ] ; then
2014-08-25 12:09:37 +00:00
# Ask the Internet.
GUESSED_IP = $( get_publicip_from_web_service 4)
# On the first run, if we got an answer from the Internet then don't
# ask the user.
2018-12-14 01:28:21 +00:00
if [ [ -z " ${ DEFAULT_PUBLIC_IP :- } " && ! -z " $GUESSED_IP " ] ] ; then
2014-08-25 12:09:37 +00:00
PUBLIC_IP = $GUESSED_IP
# Otherwise on the first run at least provide a default.
2018-12-26 20:39:47 +00:00
elif [ [ -z " ${ DEFAULT_PUBLIC_IP :- } " ] ] ; then
2014-08-25 12:09:37 +00:00
DEFAULT_PUBLIC_IP = $( get_default_privateip 4)
# On later runs, if the previous value matches the guessed value then
# don't ask the user either.
2018-12-26 20:39:47 +00:00
elif [ " ${ DEFAULT_PUBLIC_IP :- } " = = " $GUESSED_IP " ] ; then
2014-08-25 12:09:37 +00:00
PUBLIC_IP = $GUESSED_IP
fi
2018-11-30 15:24:19 +00:00
if [ -z " ${ PUBLIC_IP :- } " ] ; then
2014-08-25 12:09:37 +00:00
input_box "Public IP Address" \
" Enter the public IP address of this machine, as given to you by your ISP.
\n \n Public IP address:" \
2018-11-30 15:24:19 +00:00
${ DEFAULT_PUBLIC_IP :- } \
2014-08-25 12:09:37 +00:00
PUBLIC_IP
if [ -z " $PUBLIC_IP " ] ; then
# user hit ESC/cancel
exit
fi
fi
fi
# Same for IPv6. But it's optional. Also, if it looks like the system
# doesn't have an IPv6, don't ask for one.
2018-11-30 15:24:19 +00:00
if [ -z " ${ PUBLIC_IPV6 :- } " ] ; then
2014-08-25 12:09:37 +00:00
# Ask the Internet.
GUESSED_IP = $( get_publicip_from_web_service 6)
MATCHED = 0
2018-11-30 15:24:19 +00:00
if [ [ -z " ${ DEFAULT_PUBLIC_IPV6 :- } " && ! -z " $GUESSED_IP " ] ] ; then
2014-08-25 12:09:37 +00:00
PUBLIC_IPV6 = $GUESSED_IP
2018-11-30 15:24:19 +00:00
elif [ [ " ${ DEFAULT_PUBLIC_IPV6 :- } " = = " $GUESSED_IP " ] ] ; then
2014-08-25 12:09:37 +00:00
# No IPv6 entered and machine seems to have none, or what
# the user entered matches what the Internet tells us.
PUBLIC_IPV6 = $GUESSED_IP
MATCHED = 1
2018-11-30 15:24:19 +00:00
elif [ [ -z " ${ DEFAULT_PUBLIC_IPV6 :- } " ] ] ; then
2014-08-25 12:09:37 +00:00
DEFAULT_PUBLIC_IP = $( get_default_privateip 6)
fi
2018-11-30 15:24:19 +00:00
if [ [ -z " ${ PUBLIC_IPV6 :- } " && $MATCHED = = 0 ] ] ; then
2014-08-25 12:09:37 +00:00
input_box "IPv6 Address (Optional)" \
" Enter the public IPv6 address of this machine, as given to you by your ISP.
\n \n Leave blank if the machine does not have an IPv6 address.
2014-08-26 10:34:22 +00:00
\n \n Public IPv6 address:" \
2018-11-30 15:24:19 +00:00
${ DEFAULT_PUBLIC_IPV6 :- } \
2014-08-25 12:09:37 +00:00
PUBLIC_IPV6
if [ ! $PUBLIC_IPV6_EXITCODE ] ; then
# user hit ESC/cancel
exit
fi
fi
fi
# Get the IP addresses of the local network interface(s) that are connected
# to the Internet. We need these when we want to have services bind only to
# the public network interfaces (not loopback, not tunnel interfaces).
2018-11-30 15:24:19 +00:00
if [ -z " ${ PRIVATE_IP :- } " ] ; then
2014-08-25 12:09:37 +00:00
PRIVATE_IP = $( get_default_privateip 4)
fi
2018-11-30 15:24:19 +00:00
if [ -z " ${ PRIVATE_IPV6 :- } " ] ; then
2014-08-25 12:09:37 +00:00
PRIVATE_IPV6 = $( get_default_privateip 6)
fi
if [ [ -z " $PRIVATE_IP " && -z " $PRIVATE_IPV6 " ] ] ; then
echo
echo "I could not determine the IP or IPv6 address of the network inteface"
echo "for connecting to the Internet. Setup must stop."
echo
hostname -I
route
echo
exit
fi
2015-05-07 11:11:21 +00:00
# Automatic configuration, e.g. as used in our Vagrant configuration.
if [ " $PUBLIC_IP " = "auto" ] ; then
# Use a public API to get our public IP address, or fall back to local network configuration.
PUBLIC_IP = $( get_publicip_from_web_service 4 || get_default_privateip 4)
fi
if [ " $PUBLIC_IPV6 " = "auto" ] ; then
# Use a public API to get our public IPv6 address, or fall back to local network configuration.
PUBLIC_IPV6 = $( get_publicip_from_web_service 6 || get_default_privateip 6)
fi
2015-06-18 11:35:48 +00:00
if [ " $PRIMARY_HOSTNAME " = "auto" ] ; then
PRIMARY_HOSTNAME = $( get_default_hostname)
2015-05-07 11:11:21 +00:00
fi
# Set STORAGE_USER and STORAGE_ROOT to default values (user-data and /home/user-data), unless
# we've already got those values from a previous run.
2018-11-30 15:24:19 +00:00
if [ -z " ${ STORAGE_USER :- } " ] ; then
STORAGE_USER = $( [ [ -z " ${ DEFAULT_STORAGE_USER :- } " ] ] && echo "user-data" || echo " $DEFAULT_STORAGE_USER " )
2015-05-07 11:11:21 +00:00
fi
2018-11-30 15:24:19 +00:00
if [ -z " ${ STORAGE_ROOT :- } " ] ; then
STORAGE_ROOT = $( [ [ -z " ${ DEFAULT_STORAGE_ROOT :- } " ] ] && echo " /home/ $STORAGE_USER " || echo " $DEFAULT_STORAGE_ROOT " )
2015-05-07 11:11:21 +00:00
fi
# Show the configuration, since the user may have not entered it manually.
2019-07-27 08:03:15 +00:00
# Adapted from: https://github.com/tdulcet/Linux-System-Information/blob/master/info.sh
2018-10-25 03:31:20 +00:00
echo -e " \nLinux Distribution:\t\t ${ PRETTY_NAME :- $ID - $VERSION_ID } "
2019-07-27 08:03:15 +00:00
echo -e " Linux Kernel:\t\t\t $KERNEL "
mapfile -t CPU < <( sed -n 's/^model name[[:space:]]*: *//p' /proc/cpuinfo | uniq)
2018-10-25 03:31:20 +00:00
if [ -n " $CPU " ] ; then
echo -e " Processor (CPU):\t\t ${ CPU [*] } "
fi
2019-07-27 08:03:15 +00:00
CPU_THREADS = $( nproc --all)
CPU_CORES = $(( CPU_THREADS / $( lscpu | grep -i '^thread(s) per core' | sed -n 's/^.\+:[[:blank:]]*//p' ) ))
echo -e " CPU Cores/Threads:\t\t $CPU_CORES / $CPU_THREADS "
2018-11-02 08:07:15 +00:00
echo -e " Architecture:\t\t\t $HOSTTYPE ( ${ ARCHITECTURE } -bit) "
2018-10-25 03:31:20 +00:00
echo -e " Total memory (RAM):\t\t $( printf "%'d" $(( TOTAL_PHYSICAL_MEM / 1024 )) ) MiB ( $( printf "%'d" $(( ( ( TOTAL_PHYSICAL_MEM * 1024 ) / 1000 ) / 1000 )) ) MB) "
echo -e " Total swap space:\t\t $( printf "%'d" $(( TOTAL_SWAP / 1024 )) ) MiB ( $( printf "%'d" $(( ( ( TOTAL_SWAP * 1024 ) / 1000 ) / 1000 )) ) MB) "
if command -v lspci >/dev/null; then
2019-07-27 08:03:15 +00:00
mapfile -t GPU < <( lspci 2>/dev/null | grep -i 'vga\|3d\|2d' | sed -n 's/^.*: //p' )
2018-10-25 03:31:20 +00:00
fi
if [ -n " $GPU " ] ; then
echo -e " Graphics Processor (GPU):\t ${ GPU [*] } "
fi
echo -e " Computer name:\t\t\t $HOSTNAME "
echo -e " Primary Hostname:\t\t $PRIMARY_HOSTNAME "
if [ -n " $PUBLIC_IPV6 " ] ; then
echo -e " Public IPv4 Address:\t\t $PUBLIC_IP "
echo -e " Public IPv6 Address:\t\t $PUBLIC_IPV6 "
else
echo -e " Public IP Address:\t\t $PUBLIC_IP "
fi
if [ -n " $PRIVATE_IPV6 " ] ; then
if [ " $PRIVATE_IP " != " $PUBLIC_IP " ] ; then
echo -e " Private IPv4 Address:\t\t $PRIVATE_IP "
fi
if [ " $PRIVATE_IPV6 " != " $PUBLIC_IPV6 " ] ; then
echo -e " Private IPv6 Address:\t\t $PRIVATE_IPV6 "
fi
else
if [ " $PRIVATE_IP " != " $PUBLIC_IP " ] ; then
echo -e " Private IP Address:\t\t $PRIVATE_IP "
fi
2015-05-07 11:11:21 +00:00
fi
2019-07-27 08:03:15 +00:00
TIME_ZONE = $( timedatectl 2>/dev/null | grep -i 'time zone:\|timezone:' | sed -n 's/^.*: //p' )
2018-10-25 03:31:20 +00:00
echo -e " Time zone:\t\t\t $TIME_ZONE \n "
if command -v systemd-detect-virt >/dev/null && CONTAINER = $( systemd-detect-virt -c) ; then
echo -e " Virtualization container:\t $CONTAINER \n "
2015-05-07 11:11:21 +00:00
fi
2018-10-25 03:31:20 +00:00
if command -v systemd-detect-virt >/dev/null && VM = $( systemd-detect-virt -v) ; then
echo -e " Virtual Machine (VM) hypervisor: $VM \n "
2015-05-07 11:11:21 +00:00
fi
2018-10-25 03:31:20 +00:00
if command -v git >/dev/null && [ -d .git ] ; then
echo -e " Mail-in-a-Box Version:\t\t $( git describe) \n "
2015-05-07 11:11:21 +00:00
fi