2014-06-03 13:24:48 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
source setup/functions.sh
|
|
|
|
|
2015-08-19 19:58:35 +00:00
|
|
|
echo "Installing Mail-in-a-Box system management daemon..."
|
|
|
|
|
2017-02-01 14:14:01 +00:00
|
|
|
# DEPENDENCIES
|
|
|
|
|
|
|
|
# Install Python packages that are available from the Ubuntu
|
|
|
|
# apt repository:
|
2016-02-18 11:59:38 +00:00
|
|
|
# flask, yaml, dnspython, and dateutil are all for our Python 3 management daemon itself.
|
|
|
|
# duplicity does backups. python-pip is so we can 'pip install boto' for Python 2, for duplicity, so it can do backups to AWS S3.
|
|
|
|
apt_install python3-flask links duplicity libyaml-dev python3-dnspython python3-dateutil python-pip
|
2015-07-27 19:56:08 +00:00
|
|
|
|
2016-02-18 11:59:38 +00:00
|
|
|
# These are required to pip install cryptography.
|
|
|
|
apt_install build-essential libssl-dev libffi-dev python3-dev
|
|
|
|
|
2017-02-01 14:14:01 +00:00
|
|
|
# pip<6.1 + setuptools>=34 have a problem with packages that
|
|
|
|
# try to update setuptools during installation, like cryptography.
|
|
|
|
# See https://github.com/pypa/pip/issues/4253. The Ubuntu 14.04
|
|
|
|
# package versions are pip 1.5.4 and setuptools 3.3. When we
|
|
|
|
# install cryptography under those versions, it tries to update
|
|
|
|
# setuptools to version 34, which now creates the conflict, and
|
|
|
|
# then pip gets permanently broken with errors like
|
|
|
|
# "ImportError: No module named 'packaging'".
|
|
|
|
#
|
|
|
|
# Let's test for the error:
|
|
|
|
if ! python3 -c "from pkg_resources import load_entry_point" 2&> /dev/null; then
|
|
|
|
# This system seems to be broken already.
|
|
|
|
echo "Fixing broken pip and setuptools..."
|
|
|
|
rm -rf /usr/local/lib/python3.4/dist-packages/{pkg_resources,setuptools}*
|
|
|
|
apt-get install --reinstall python3-setuptools python3-pip python3-pkg-resources
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# The easiest work-around on systems that aren't already broken is
|
|
|
|
# to upgrade pip (to >=9.0.1) and setuptools (to >=34.1) individually
|
|
|
|
# before we install any package that tries to update setuptools.
|
|
|
|
hide_output pip3 install --upgrade pip
|
|
|
|
hide_output pip3 install --upgrade setuptools
|
|
|
|
|
2016-02-18 11:59:38 +00:00
|
|
|
# Install other Python 3 packages used by the management daemon.
|
|
|
|
# The first line is the packages that Josh maintains himself!
|
|
|
|
# NOTE: email_validator is repeated in setup/questions.sh, so please keep the versions synced.
|
2017-02-01 16:00:54 +00:00
|
|
|
# Force acme to be updated because it seems to need it after the
|
|
|
|
# pip/setuptools breakage (see above) and the ACME protocol may
|
|
|
|
# have changed (I got an error on one of my systems).
|
2015-10-10 22:03:55 +00:00
|
|
|
hide_output pip3 install --upgrade \
|
2017-01-01 22:11:31 +00:00
|
|
|
rtyaml "email_validator>=1.0.0" "free_tls_certificates>=0.1.3" "exclusiveprocess" \
|
2017-02-01 16:00:54 +00:00
|
|
|
"idna>=2.0.0" "cryptography>=1.0.2" acme boto psutil
|
2014-06-03 20:21:17 +00:00
|
|
|
|
2016-02-18 11:54:23 +00:00
|
|
|
# duplicity uses python 2 so we need to get the python 2 package of boto to have backups to S3.
|
|
|
|
# boto from the Ubuntu package manager is too out-of-date -- it doesn't support the newer
|
|
|
|
# S3 api used in some regions, which breaks backups to those regions. See #627, #653.
|
2017-02-10 14:44:40 +00:00
|
|
|
hide_output pip2 install --upgrade boto
|
2016-02-18 11:54:23 +00:00
|
|
|
|
2017-02-01 14:14:01 +00:00
|
|
|
# CONFIGURATION
|
|
|
|
|
2014-06-03 20:21:17 +00:00
|
|
|
# Create a backup directory and a random key for encrypting backups.
|
|
|
|
mkdir -p $STORAGE_ROOT/backup
|
|
|
|
if [ ! -f $STORAGE_ROOT/backup/secret_key.txt ]; then
|
2014-08-22 21:23:56 +00:00
|
|
|
$(umask 077; openssl rand -base64 2048 > $STORAGE_ROOT/backup/secret_key.txt)
|
2014-06-03 20:21:17 +00:00
|
|
|
fi
|
2014-06-03 13:24:48 +00:00
|
|
|
|
2017-05-08 11:25:16 +00:00
|
|
|
|
|
|
|
# Download jQuery and Bootstrap local files
|
|
|
|
|
|
|
|
# Make sure we have the directory to save to.
|
2017-05-23 23:22:53 +00:00
|
|
|
assets_dir=/usr/local/lib/mailinabox/vendor/assets
|
2017-05-31 11:36:17 +00:00
|
|
|
rm -rf $assets_dir
|
2017-05-08 11:25:16 +00:00
|
|
|
mkdir -p $assets_dir
|
|
|
|
|
|
|
|
# jQuery CDN URL
|
|
|
|
jquery_version=2.1.4
|
|
|
|
jquery_url=https://code.jquery.com
|
|
|
|
|
|
|
|
# Get jQuery
|
|
|
|
wget_verify $jquery_url/jquery-$jquery_version.min.js 43dc554608df885a59ddeece1598c6ace434d747 $assets_dir/jquery.min.js
|
|
|
|
|
|
|
|
# Bootstrap CDN URL
|
|
|
|
bootstrap_version=3.3.7
|
2017-05-31 11:36:17 +00:00
|
|
|
bootstrap_url=https://github.com/twbs/bootstrap/releases/download/v$bootstrap_version/bootstrap-$bootstrap_version-dist.zip
|
2017-05-08 11:25:16 +00:00
|
|
|
|
|
|
|
# Get Bootstrap
|
2017-05-31 11:36:17 +00:00
|
|
|
wget_verify $bootstrap_url e6b1000b94e835ffd37f4c6dcbdad43f4b48a02a /tmp/bootstrap.zip
|
|
|
|
unzip -q /tmp/bootstrap.zip -d /usr/local/lib/mailinabox/vendor/assets
|
|
|
|
mv /usr/local/lib/mailinabox/vendor/assets/bootstrap-$bootstrap_version-dist /usr/local/lib/mailinabox/vendor/assets/bootstrap
|
|
|
|
rm -f /tmp/bootstrap.zip
|
2017-05-08 11:25:16 +00:00
|
|
|
|
2014-06-03 13:24:48 +00:00
|
|
|
# Link the management server daemon into a well known location.
|
2014-06-21 16:35:00 +00:00
|
|
|
rm -f /usr/local/bin/mailinabox-daemon
|
|
|
|
ln -s `pwd`/management/daemon.py /usr/local/bin/mailinabox-daemon
|
2014-06-03 13:24:48 +00:00
|
|
|
|
|
|
|
# Create an init script to start the management daemon and keep it
|
|
|
|
# running after a reboot.
|
|
|
|
rm -f /etc/init.d/mailinabox
|
|
|
|
ln -s $(pwd)/conf/management-initscript /etc/init.d/mailinabox
|
2014-07-16 13:06:45 +00:00
|
|
|
hide_output update-rc.d mailinabox defaults
|
2014-06-03 13:24:48 +00:00
|
|
|
|
2015-12-26 13:39:22 +00:00
|
|
|
# Remove old files we no longer use.
|
|
|
|
rm -f /etc/cron.daily/mailinabox-backup
|
|
|
|
rm -f /etc/cron.daily/mailinabox-statuschecks
|
2014-06-26 10:46:22 +00:00
|
|
|
|
2015-12-26 13:39:22 +00:00
|
|
|
# Perform nightly tasks at 3am in system time: take a backup, run
|
|
|
|
# status checks and email the administrator any changes.
|
2015-12-23 22:29:13 +00:00
|
|
|
|
2015-12-26 13:39:22 +00:00
|
|
|
cat > /etc/cron.d/mailinabox-nightly << EOF;
|
2015-03-08 21:56:28 +00:00
|
|
|
# Mail-in-a-Box --- Do not edit / will be overwritten on update.
|
2015-12-26 13:39:22 +00:00
|
|
|
# Run nightly tasks: backup, status checks.
|
|
|
|
0 3 * * * root (cd `pwd` && management/daily_tasks.sh)
|
2015-03-08 21:56:28 +00:00
|
|
|
EOF
|
|
|
|
|
2015-10-10 22:03:55 +00:00
|
|
|
# Start the management server.
|
2014-07-16 13:06:45 +00:00
|
|
|
restart_service mailinabox
|