#!/bin/sh

set -eu

if [ "$(id -u)" -ne 0 ]; then
    echo "nemesis-init-admin must be run through sudo or as root" >&2
    exit 1
fi

if ! command -v runuser >/dev/null 2>&1; then
    echo "nemesis-init-admin requires runuser from util-linux" >&2
    exit 1
fi

if ! id nemesis-web >/dev/null 2>&1; then
    echo "the nemesis-web service account is missing; repair the Nemesis package first" >&2
    exit 1
fi

exec runuser -u nemesis-web -- /usr/bin/nemesis-web init-admin "$@"
