#!/bin/sh
# It's very important to set user/group correctly.

authentik_dir='/var/lib/authentik'

if ! getent group authentik 1>/dev/null; then
	echo '* Creating group authentik' 1>&2

	addgroup -S authentik
fi

if ! id authentik 2>/dev/null 1>&2; then
	echo '* Creating user authentik' 1>&2

	adduser -DHS -G authentik -h "$authentik_dir" -s /bin/sh  \
		-g "added by apk for authentik" authentik
	passwd -u authentik 1>/dev/null  # unlock
fi

if ! id -Gn authentik | grep -Fq redis; then
	echo '* Adding user authentik to group redis' 1>&2

	addgroup authentik redis
fi

exit 0