#!/bin/sh
set -e

case "$1" in
    configure)
        # Prefer systemd-sysusers to create the service user.
        if [ -d /run/systemd/system ] && [ -x /usr/bin/systemd-sysusers ]; then
            systemd-sysusers openlist.conf
        else
            # fallback: manual user creation (non-systemd systems)
            if ! getent passwd openlist >/dev/null; then
                adduser --system --group --no-create-home --home /nonexistent \
                    --gecos "OpenList Service" openlist
            fi
        fi

        # State / config directories (also declared via StateDirectory and
        # ConfigurationDirectory in the unit; keep for non-systemd installs).
        mkdir -p /var/lib/openlist /etc/openlist
        chown openlist:openlist /var/lib/openlist /etc/openlist
        chmod 750 /var/lib/openlist /etc/openlist
        ;;
esac

#DEBHELPER#

exit 0
