#!/bin/sh
set -e

# Create the `restard` system user if missing. Idempotent: a re-install
# or upgrade re-runs this script, but getent guard prevents duplicate
# useradd invocations.
if ! getent passwd restard >/dev/null; then
    useradd --system --user-group --home-dir /var/lib/restard restard
fi

# /var/lib/restard was created by debian/dirs as root; fix ownership
# so the runtime user can write there.
chown restard:restard /var/lib/restard
chmod 0750 /var/lib/restard

# Reload systemd so the freshly-installed unit file is visible. Skip on
# chroots / non-systemd build environments.
if [ -d /run/systemd/system ]; then
    systemctl daemon-reload || true
fi

# Do NOT start the service. Operator must configure /etc/default/restard
# and the token credential files first, then `systemctl start restard`.
exit 0