78d71498fa
* Add the PHP PPA. * Specify the version when invoking the php CLI. * Specify the version in package names. * Update paths to 8.0 (using a variable in the setup scripts). * Update z-push's php-xsl dependency to php8.0-xml. * php-json is now built-into PHP. Although PHP 8.1 is the stock version in Ubuntu 22.04, it's not supported by Nextcloud yet, and it likely will never be supported by the the version of Nextcloud that succeeds the last version of Nextcloud that supports PHP 7.2, and we have to install the next version so that an upgrade is permitted, so skipping to PHP 8.1 may not be easily possible.
120 lines
4.1 KiB
Bash
Executable file
120 lines
4.1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
source setup/functions.sh
|
|
|
|
echo "Installing Mail-in-a-Box system management daemon..."
|
|
|
|
# DEPENDENCIES
|
|
|
|
# We used to install management daemon-related Python packages
|
|
# directly to /usr/local/lib. We moved to a virtualenv because
|
|
# these packages might conflict with apt-installed packages.
|
|
# We may have a lingering version of acme that conflcits with
|
|
# certbot, which we're about to install below, so remove it
|
|
# first. Once acme is installed by an apt package, this might
|
|
# break the package version and `apt-get install --reinstall python3-acme`
|
|
# might be needed in that case.
|
|
while [ -d /usr/local/lib/python3.4/dist-packages/acme ]; do
|
|
pip3 uninstall -y acme;
|
|
done
|
|
|
|
# duplicity is used to make backups of user data.
|
|
#
|
|
# virtualenv is used to isolate the Python 3 packages we
|
|
# install via pip from the system-installed packages.
|
|
#
|
|
# certbot installs EFF's certbot which we use to
|
|
# provision free TLS certificates.
|
|
apt_install duplicity python3-pip virtualenv certbot rsync
|
|
|
|
# b2sdk is used for backblaze backups.
|
|
# boto is used for amazon aws backups.
|
|
# Both are installed outside the pipenv, so they can be used by duplicity
|
|
hide_output pip3 install --upgrade b2sdk boto
|
|
|
|
# Create a virtualenv for the installation of Python 3 packages
|
|
# used by the management daemon.
|
|
inst_dir=/usr/local/lib/mailinabox
|
|
mkdir -p $inst_dir
|
|
venv=$inst_dir/env
|
|
if [ ! -d $venv ]; then
|
|
hide_output virtualenv -ppython3 $venv
|
|
fi
|
|
|
|
# Upgrade pip because the Ubuntu-packaged version is out of date.
|
|
hide_output $venv/bin/pip install --upgrade pip
|
|
|
|
# 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.
|
|
hide_output $venv/bin/pip install --upgrade \
|
|
rtyaml "email_validator>=1.0.0" "exclusiveprocess" \
|
|
flask dnspython python-dateutil expiringdict \
|
|
qrcode[pil] pyotp \
|
|
"idna>=2.0.0" "cryptography==2.2.2" psutil postfix-mta-sts-resolver \
|
|
b2sdk boto
|
|
|
|
# CONFIGURATION
|
|
|
|
# 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
|
|
$(umask 077; openssl rand -base64 2048 > $STORAGE_ROOT/backup/secret_key.txt)
|
|
fi
|
|
|
|
|
|
# Download jQuery and Bootstrap local files
|
|
|
|
# Make sure we have the directory to save to.
|
|
assets_dir=$inst_dir/vendor/assets
|
|
rm -rf $assets_dir
|
|
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
|
|
bootstrap_url=https://github.com/twbs/bootstrap/releases/download/v$bootstrap_version/bootstrap-$bootstrap_version-dist.zip
|
|
|
|
# Get Bootstrap
|
|
wget_verify $bootstrap_url e6b1000b94e835ffd37f4c6dcbdad43f4b48a02a /tmp/bootstrap.zip
|
|
unzip -q /tmp/bootstrap.zip -d $assets_dir
|
|
mv $assets_dir/bootstrap-$bootstrap_version-dist $assets_dir/bootstrap
|
|
rm -f /tmp/bootstrap.zip
|
|
|
|
# Create an init script to start the management daemon and keep it
|
|
# running after a reboot.
|
|
cat > $inst_dir/start <<EOF;
|
|
#!/bin/bash
|
|
# Set character encoding flags to ensure that any non-ASCII don't cause problems.
|
|
export LANGUAGE=en_US.UTF-8
|
|
export LC_ALL=en_US.UTF-8
|
|
export LANG=en_US.UTF-8
|
|
export LC_TYPE=en_US.UTF-8
|
|
|
|
source $venv/bin/activate
|
|
exec python $(pwd)/management/daemon.py
|
|
EOF
|
|
chmod +x $inst_dir/start
|
|
cp --remove-destination conf/mailinabox.service /lib/systemd/system/mailinabox.service # target was previously a symlink so remove it first
|
|
hide_output systemctl link -f /lib/systemd/system/mailinabox.service
|
|
hide_output systemctl daemon-reload
|
|
hide_output systemctl enable mailinabox.service
|
|
|
|
# Perform nightly tasks at 3am in system time: take a backup, run
|
|
# status checks and email the administrator any changes.
|
|
|
|
minute=$((RANDOM % 60)) # avoid overloading mailinabox.email
|
|
cat > /etc/cron.d/mailinabox-nightly << EOF;
|
|
# Mail-in-a-Box --- Do not edit / will be overwritten on update.
|
|
# Run nightly tasks: backup, status checks.
|
|
$minute 3 * * * root (cd $(pwd) && management/daily_tasks.sh)
|
|
EOF
|
|
|
|
# Start the management server.
|
|
restart_service mailinabox
|