#!/bin/bash -e

# Add service account
useradd -r mxids || true

# Set permissions for data directory
chown -R mxids:mxids %DEB_DATA_DIR%

# Create symlink to mxids run script
ln -sfT /usr/lib/mxids/mxids /usr/bin/mxids

# Enable systemd service
systemctl enable mxids.service

# If we already have a config file setup, we attempt to run mxids automatically
# Specifically targeted at upgrades where the service needs to be restarted
if [ -f "%DEB_CONF_FILE%" ]; then
    systemctl restart mxids.service
fi
