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..."
|
|
|
|
|
2015-11-26 14:20:59 +00:00
|
|
|
# Switching python 2 boto to package manager's, not pypi's.
|
|
|
|
if [ -f /usr/local/lib/python2.7/dist-packages/boto/__init__.py ]; then hide_output pip uninstall -y boto; fi
|
|
|
|
|
|
|
|
# duplicity uses python 2 so we need to use the python 2 package of boto
|
2015-06-21 14:36:41 +00:00
|
|
|
# build-essential libssl-dev libffi-dev python3-dev: Required to pip install cryptography.
|
2015-11-26 14:20:59 +00:00
|
|
|
apt_install python3-flask links duplicity python-boto libyaml-dev python3-dnspython python3-dateutil \
|
2015-07-26 16:25:52 +00:00
|
|
|
build-essential libssl-dev libffi-dev python3-dev python-pip
|
2015-07-27 19:56:08 +00:00
|
|
|
|
2015-10-10 22:03:55 +00:00
|
|
|
# Install other Python packages. The first line is the packages that Josh maintains himself!
|
|
|
|
hide_output pip3 install --upgrade \
|
2016-02-16 14:08:58 +00:00
|
|
|
rtyaml "email_validator>=1.0.0" "free_tls_certificates>=0.1.3" \
|
2015-10-10 22:03:55 +00:00
|
|
|
"idna>=2.0.0" "cryptography>=1.0.2" boto psutil
|
2015-07-27 19:56:08 +00:00
|
|
|
# email_validator is repeated in setup/questions.sh
|
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
|
|
|
|
|
|
|
# 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
|