2014-04-23 22:54:05 +00:00
|
|
|
#!/bin/bash
|
2013-09-01 14:13:51 +00:00
|
|
|
# This is the entry point for configuring the system.
|
|
|
|
#####################################################
|
|
|
|
|
2014-06-07 17:54:58 +00:00
|
|
|
source setup/functions.sh # load our functions
|
|
|
|
|
2013-08-31 13:05:58 +00:00
|
|
|
# Check system setup.
|
2013-09-01 14:13:51 +00:00
|
|
|
|
2014-04-18 00:17:24 +00:00
|
|
|
if [ "`lsb_release -d | sed 's/.*:\s*//'`" != "Ubuntu 14.04 LTS" ]; then
|
|
|
|
echo "Mail-in-a-Box only supports being installed on Ubuntu 14.04, sorry. You are running:"
|
2014-03-17 00:42:00 +00:00
|
|
|
echo
|
|
|
|
lsb_release -d | sed 's/.*:\s*//'
|
|
|
|
echo
|
|
|
|
echo "We can't write scripts that run on every possible setup, sorry."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2014-06-03 21:31:13 +00:00
|
|
|
# Recall the last settings used if we're running this a second time.
|
|
|
|
if [ -f /etc/mailinabox.conf ]; then
|
|
|
|
cat /etc/mailinabox.conf | sed s/^/DEFAULT_/ > /tmp/mailinabox.prev.conf
|
|
|
|
source /tmp/mailinabox.prev.conf
|
|
|
|
fi
|
2013-08-31 13:05:58 +00:00
|
|
|
|
2013-09-01 14:13:51 +00:00
|
|
|
# Gather information from the user about the hostname and public IP
|
|
|
|
# address of this host.
|
2013-08-26 21:01:48 +00:00
|
|
|
if [ -z "$PUBLIC_HOSTNAME" ]; then
|
|
|
|
echo
|
|
|
|
echo "Enter the hostname you want to assign to this machine."
|
|
|
|
echo "We've guessed a value. Just backspace it if it's wrong."
|
|
|
|
echo "Josh uses box.occams.info as his hostname. Yours should"
|
|
|
|
echo "be similar."
|
2013-08-31 14:46:10 +00:00
|
|
|
echo
|
2014-06-03 21:31:13 +00:00
|
|
|
|
|
|
|
if [ -z "$DEFAULT_PUBLIC_HOSTNAME" ]; then
|
|
|
|
# set a default on first run
|
2014-06-07 17:54:58 +00:00
|
|
|
DEFAULT_PUBLIC_HOSTNAME=`get_default_hostname`
|
2014-06-03 21:31:13 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
read -e -i "$DEFAULT_PUBLIC_HOSTNAME" -p "Hostname: " PUBLIC_HOSTNAME
|
2013-08-26 21:01:48 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$PUBLIC_IP" ]; then
|
|
|
|
echo
|
|
|
|
echo "Enter the public IP address of this machine, as given to"
|
|
|
|
echo "you by your ISP. We've guessed a value, but just backspace"
|
|
|
|
echo "it if it's wrong."
|
2013-08-31 14:46:10 +00:00
|
|
|
echo
|
2014-06-03 21:31:13 +00:00
|
|
|
|
|
|
|
if [ -z "$DEFAULT_PUBLIC_IP" ]; then
|
|
|
|
# set a default on first run
|
2014-06-07 17:54:58 +00:00
|
|
|
DEFAULT_PUBLIC_IP=`get_default_publicip`
|
2014-06-03 21:31:13 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
read -e -i "$DEFAULT_PUBLIC_IP" -p "Public IP: " PUBLIC_IP
|
2013-08-26 21:01:48 +00:00
|
|
|
fi
|
|
|
|
|
2014-06-03 21:17:10 +00:00
|
|
|
if [ -z "$CSR_COUNTRY" ]; then
|
|
|
|
echo
|
|
|
|
echo "Enter the two-letter, uppercase country code for where you"
|
|
|
|
echo "live or where your organization is based. (This is used to"
|
|
|
|
echo "create an SSL certificate.)"
|
|
|
|
echo
|
2014-06-03 21:31:13 +00:00
|
|
|
|
|
|
|
#if [ -z "$DEFAULT_CSR_COUNTRY" ]; then
|
|
|
|
# # set a default on first run
|
|
|
|
# DEFAULT_CSR_COUNTRY=...?
|
|
|
|
#fi
|
|
|
|
|
|
|
|
read -e -i "$DEFAULT_CSR_COUNTRY" -p "Country Code: " CSR_COUNTRY
|
2014-06-03 21:17:10 +00:00
|
|
|
fi
|
|
|
|
|
2014-06-04 23:39:58 +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.
|
2014-06-07 18:55:57 +00:00
|
|
|
PUBLIC_IP=`get_default_publicip`
|
2014-06-04 23:39:58 +00:00
|
|
|
echo "IP Address: $PUBLIC_IP"
|
|
|
|
fi
|
|
|
|
if [ "$PUBLIC_HOSTNAME" == "auto-easy" ]; then
|
|
|
|
# Generate a probably-unique subdomain under our justtesting.email domain.
|
2014-06-07 18:55:57 +00:00
|
|
|
PUBLIC_HOSTNAME=m`get_default_publicip | sha1sum | cut -c1-5`.justtesting.email
|
2014-06-04 23:39:58 +00:00
|
|
|
echo "Public Hostname: $PUBLIC_HOSTNAME"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2014-04-25 12:25:07 +00:00
|
|
|
# Create the user named "user-data" and store all persistent user
|
2013-09-01 14:13:51 +00:00
|
|
|
# data (mailboxes, etc.) in that user's home directory.
|
2013-08-26 21:01:48 +00:00
|
|
|
if [ -z "$STORAGE_ROOT" ]; then
|
2013-09-01 14:13:51 +00:00
|
|
|
STORAGE_USER=user-data
|
|
|
|
if [ ! -d /home/$STORAGE_USER ]; then useradd -m $STORAGE_USER; fi
|
|
|
|
STORAGE_ROOT=/home/$STORAGE_USER
|
2013-08-31 13:05:58 +00:00
|
|
|
mkdir -p $STORAGE_ROOT
|
2013-08-26 21:01:48 +00:00
|
|
|
fi
|
|
|
|
|
2013-09-01 14:13:51 +00:00
|
|
|
# Save the global options in /etc/mailinabox.conf so that standalone
|
|
|
|
# tools know where to look for data.
|
2013-08-31 14:46:10 +00:00
|
|
|
cat > /etc/mailinabox.conf << EOF;
|
|
|
|
STORAGE_ROOT=$STORAGE_ROOT
|
2013-08-31 18:52:13 +00:00
|
|
|
PUBLIC_HOSTNAME=$PUBLIC_HOSTNAME
|
2013-09-08 11:47:27 +00:00
|
|
|
PUBLIC_IP=$PUBLIC_IP
|
2014-06-03 21:17:10 +00:00
|
|
|
CSR_COUNTRY=$CSR_COUNTRY
|
2013-08-31 14:46:10 +00:00
|
|
|
EOF
|
|
|
|
|
2013-09-01 14:13:51 +00:00
|
|
|
# Start service configuration.
|
2014-06-03 11:12:38 +00:00
|
|
|
. setup/system.sh
|
|
|
|
. setup/dns.sh
|
|
|
|
. setup/mail.sh
|
|
|
|
. setup/dkim.sh
|
|
|
|
. setup/spamassassin.sh
|
|
|
|
. setup/web.sh
|
|
|
|
. setup/webmail.sh
|
2014-06-03 13:24:48 +00:00
|
|
|
. setup/management.sh
|
|
|
|
|
|
|
|
# Write the DNS configuration files.
|
2014-06-04 23:39:58 +00:00
|
|
|
sleep 5 # wait for the daemon to start
|
2014-06-06 12:41:57 +00:00
|
|
|
curl -s -d POSTDATA http://127.0.0.1:10222/dns/update
|
2013-09-01 14:39:36 +00:00
|
|
|
|
2014-06-04 23:39:58 +00:00
|
|
|
# If there aren't any mail users yet, create one.
|
2014-01-27 15:41:59 +00:00
|
|
|
if [ -z "`tools/mail.py user`" ]; then
|
2013-09-01 14:39:36 +00:00
|
|
|
# The outut of "tools/mail.py user" is a list of mail users. If there
|
2014-06-04 23:39:58 +00:00
|
|
|
# aren't any yet, it'll be empty.
|
|
|
|
|
|
|
|
# In an interactive shell, ask the user for an email address.
|
|
|
|
if [ -t 0 ]; then
|
|
|
|
echo
|
|
|
|
echo "Let's create your first mail user."
|
|
|
|
read -e -i "user@$PUBLIC_HOSTNAME" -p "Email Address: " EMAIL_ADDR
|
|
|
|
else
|
|
|
|
# Use me@PUBLIC_HOSTNAME
|
|
|
|
EMAIL_ADDR=me@$PUBLIC_HOSTNAME
|
|
|
|
EMAIL_PW=1234
|
|
|
|
echo
|
|
|
|
echo "Creating a new mail account for $EMAIL_ADDR with password $EMAIL_PW."
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
|
|
|
|
tools/mail.py user add $EMAIL_ADDR $EMAIL_PW # will ask for password if none given
|
2013-09-08 10:16:09 +00:00
|
|
|
tools/mail.py alias add hostmaster@$PUBLIC_HOSTNAME $EMAIL_ADDR
|
2014-04-24 11:58:53 +00:00
|
|
|
tools/mail.py alias add postmaster@$PUBLIC_HOSTNAME $EMAIL_ADDR
|
2013-09-01 14:39:36 +00:00
|
|
|
fi
|
2014-06-03 13:24:48 +00:00
|
|
|
|