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
|
|
|
|
|
2014-08-25 12:09:37 +00:00
|
|
|
# Check system setup: Are we running as root on Ubuntu 14.04 on a
|
|
|
|
# machine with enough memory? If not, this shows an error and exits.
|
|
|
|
. setup/preflight.sh
|
2014-07-16 12:27:14 +00:00
|
|
|
|
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
|
2014-06-30 20:41:29 +00:00
|
|
|
# Run any system migrations before proceeding. Since this is a second run,
|
|
|
|
# we assume we have Python already installed.
|
2014-07-10 12:49:19 +00:00
|
|
|
setup/migrate.py --migrate
|
2014-06-30 20:41:29 +00:00
|
|
|
|
2014-08-03 21:41:32 +00:00
|
|
|
# Load the old .conf file to get existing configuration options loaded
|
|
|
|
# into variables with a DEFAULT_ prefix.
|
2014-06-03 21:31:13 +00:00
|
|
|
cat /etc/mailinabox.conf | sed s/^/DEFAULT_/ > /tmp/mailinabox.prev.conf
|
|
|
|
source /tmp/mailinabox.prev.conf
|
2014-08-03 21:41:32 +00:00
|
|
|
rm -f /tmp/mailinabox.prev.conf
|
2014-06-03 21:31:13 +00:00
|
|
|
fi
|
2013-08-31 13:05:58 +00:00
|
|
|
|
2014-08-25 12:09:37 +00:00
|
|
|
# Ask the user for the PRIMARY_HOSTNAME, PUBLIC_IP, PUBLIC_IPV6, and CSR_COUNTRY
|
|
|
|
# if values have not already been set in environment variables. When running
|
|
|
|
# non-interactively, be sure to set values for all!
|
|
|
|
. setup/questions.sh
|
2014-06-03 21:17:10 +00:00
|
|
|
|
2014-06-04 23:39:58 +00:00
|
|
|
# Automatic configuration, e.g. as used in our Vagrant configuration.
|
2014-06-08 22:32:52 +00:00
|
|
|
if [ "$PUBLIC_IP" = "auto" ]; then
|
2014-07-30 00:04:50 +00:00
|
|
|
# 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)
|
2014-06-04 23:39:58 +00:00
|
|
|
fi
|
2014-06-08 22:32:52 +00:00
|
|
|
if [ "$PUBLIC_IPV6" = "auto" ]; then
|
2014-07-30 00:04:50 +00:00
|
|
|
# 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)
|
2014-06-08 22:32:52 +00:00
|
|
|
fi
|
2014-06-30 13:15:36 +00:00
|
|
|
if [ "$PRIMARY_HOSTNAME" = "auto-easy" ]; then
|
2014-06-04 23:39:58 +00:00
|
|
|
# Generate a probably-unique subdomain under our justtesting.email domain.
|
2014-07-30 00:04:50 +00:00
|
|
|
PRIMARY_HOSTNAME=`echo $PUBLIC_IP | sha1sum | cut -c1-5`.justtesting.email
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Show the configuration, since the user may have not entered it manually.
|
|
|
|
echo
|
|
|
|
echo "Primary Hostname: $PRIMARY_HOSTNAME"
|
|
|
|
echo "Public IP Address: $PUBLIC_IP"
|
|
|
|
if [ ! -z "$PUBLIC_IPV6" ]; then
|
|
|
|
echo "Public IPv6 Address: $PUBLIC_IPV6"
|
|
|
|
fi
|
|
|
|
if [ "$PRIVATE_IP" != "$PUBLIC_IP" ]; then
|
|
|
|
echo "Private IP Address: $PRIVATE_IP"
|
|
|
|
fi
|
|
|
|
if [ "$PRIVATE_IPV6" != "$PUBLIC_IPV6" ]; then
|
|
|
|
echo "Private IPv6 Address: $PRIVATE_IPV6"
|
2014-06-04 23:39:58 +00:00
|
|
|
fi
|
2014-09-01 11:29:34 +00:00
|
|
|
if [ -f /usr/bin/git ]; then
|
|
|
|
echo "Mail-in-a-Box Version: " $(git describe)
|
|
|
|
fi
|
2014-07-30 00:04:50 +00:00
|
|
|
echo
|
2014-06-04 23:39:58 +00:00
|
|
|
|
2014-07-26 15:26:59 +00:00
|
|
|
# Run some network checks to make sure setup on this machine makes sense.
|
2014-07-29 23:09:08 +00:00
|
|
|
if [ -z "$SKIP_NETWORK_CHECKS" ]; then
|
|
|
|
. setup/network-checks.sh
|
|
|
|
fi
|
2014-06-04 23:39:58 +00:00
|
|
|
|
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
|
2014-08-03 21:41:32 +00:00
|
|
|
echo $(setup/migrate.py --current) > $STORAGE_ROOT/mailinabox.version
|
|
|
|
chown $STORAGE_USER.$STORAGE_USER $STORAGE_ROOT/mailinabox.version
|
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;
|
2014-06-20 01:16:38 +00:00
|
|
|
STORAGE_USER=$STORAGE_USER
|
2013-08-31 14:46:10 +00:00
|
|
|
STORAGE_ROOT=$STORAGE_ROOT
|
2014-06-30 13:15:36 +00:00
|
|
|
PRIMARY_HOSTNAME=$PRIMARY_HOSTNAME
|
2013-09-08 11:47:27 +00:00
|
|
|
PUBLIC_IP=$PUBLIC_IP
|
2014-06-08 22:32:52 +00:00
|
|
|
PUBLIC_IPV6=$PUBLIC_IPV6
|
2014-07-29 23:24:10 +00:00
|
|
|
PRIVATE_IP=$PRIVATE_IP
|
|
|
|
PRIVATE_IPV6=$PRIVATE_IPV6
|
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
|
2014-06-21 22:15:53 +00:00
|
|
|
. setup/ssl.sh
|
2014-06-03 11:12:38 +00:00
|
|
|
. setup/dns.sh
|
2014-07-10 07:18:01 +00:00
|
|
|
. setup/mail-postfix.sh
|
|
|
|
. setup/mail-dovecot.sh
|
|
|
|
. setup/mail-users.sh
|
2014-06-03 11:12:38 +00:00
|
|
|
. setup/dkim.sh
|
|
|
|
. setup/spamassassin.sh
|
|
|
|
. setup/web.sh
|
2014-08-12 11:36:40 +00:00
|
|
|
. setup/webmail.sh
|
2014-08-11 14:24:29 +00:00
|
|
|
. setup/owncloud.sh
|
2014-07-12 00:04:56 +00:00
|
|
|
. setup/zpush.sh
|
2014-06-03 13:24:48 +00:00
|
|
|
. setup/management.sh
|
|
|
|
|
2014-06-20 01:16:38 +00:00
|
|
|
# Write the DNS and nginx configuration files.
|
2014-06-04 23:39:58 +00:00
|
|
|
sleep 5 # wait for the daemon to start
|
2014-06-22 00:02:52 +00:00
|
|
|
curl -s -d POSTDATA --user $(</var/lib/mailinabox/api.key): http://127.0.0.1:10222/dns/update
|
|
|
|
curl -s -d POSTDATA --user $(</var/lib/mailinabox/api.key): http://127.0.0.1:10222/web/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-08-25 12:09:37 +00:00
|
|
|
. setup/firstuser.sh
|
2014-06-03 13:24:48 +00:00
|
|
|
|
2014-08-25 12:09:37 +00:00
|
|
|
# Done.
|
2014-08-17 22:43:57 +00:00
|
|
|
echo
|
|
|
|
echo "-----------------------------------------------"
|
|
|
|
echo
|
|
|
|
echo Your Mail-in-a-Box is running.
|
|
|
|
echo
|
|
|
|
echo Please log in to the control panel for further instructions at:
|
|
|
|
echo
|
2014-08-21 10:43:55 +00:00
|
|
|
if management/status_checks.py --check-primary-hostname; then
|
2014-08-17 22:43:57 +00:00
|
|
|
# Show the nice URL if it appears to be resolving and has a valid certificate.
|
|
|
|
echo https://$PRIMARY_HOSTNAME/admin
|
|
|
|
echo
|
2014-08-26 16:12:29 +00:00
|
|
|
echo If you have a DNS problem use the box\'s IP address and check the SSL fingerprint:
|
|
|
|
echo https://$PUBLIC_IP/admin
|
|
|
|
else
|
|
|
|
echo https://$PUBLIC_IP/admin
|
|
|
|
echo
|
|
|
|
echo You will be alerted that the website has an invalid certificate. Check that
|
|
|
|
echo the certificate fingerprint matches:
|
2014-08-17 22:43:57 +00:00
|
|
|
echo
|
|
|
|
fi
|
|
|
|
openssl x509 -in $STORAGE_ROOT/ssl/ssl_certificate.pem -noout -fingerprint \
|
|
|
|
| sed "s/SHA1 Fingerprint=//"
|
|
|
|
echo
|
|
|
|
echo Then you can confirm the security exception and continue.
|
|
|
|
echo
|
|
|
|
|