#!/bin/sh
set -e

if ! command -v systemctl > /dev/null
then
    # Add mympd user only for none-systemd installations
    echo "Checking status of mympd system user and group"
    getent group mympd > /dev/null || groupadd -r mympd
    getent passwd mympd > /dev/null || useradd -r -g mympd -s /bin/false -d /var/lib/mympd mympd
else
    ! systemctl -q is-active mympd || systemctl stop mympd
    echo "Removing obsolet mympd user and group"
    ! getent passwd mympd > /dev/null || userdel mympd
    ! getent group mympd > /dev/null || groupdel mympd
fi

exit 0
