#!/bin/sh
set -e

# Create the prism system user and group if they don't exist.
# Works on deb, rpm, and apk (Alpine).

if ! getent group prism >/dev/null 2>&1; then
    if command -v groupadd >/dev/null 2>&1; then
        groupadd --system prism
    elif command -v addgroup >/dev/null 2>&1; then
        addgroup -S prism
    fi
fi

if ! getent passwd prism >/dev/null 2>&1; then
    if command -v useradd >/dev/null 2>&1; then
        useradd --system \
            --gid prism \
            --home-dir /var/lib/prism \
            --shell /usr/sbin/nologin \
            --comment "PRISM dynamic rendering proxy" \
            prism
    elif command -v adduser >/dev/null 2>&1; then
        adduser -S -G prism -h /var/lib/prism -s /sbin/nologin -D prism
    fi
fi
