#!/bin/sh
set -e

# Create trident system user and group if they don't exist
if ! getent group trident >/dev/null 2>&1; then
    if command -v groupadd >/dev/null 2>&1; then
        groupadd --system trident
    elif command -v addgroup >/dev/null 2>&1; then
        addgroup -S trident
    fi
fi

if ! getent passwd trident >/dev/null 2>&1; then
    if command -v useradd >/dev/null 2>&1; then
        useradd --system --gid trident --home-dir /var/lib/trident \
            --shell /usr/sbin/nologin --comment "Trident HTTP Cache Proxy" trident
    elif command -v adduser >/dev/null 2>&1; then
        adduser -S -G trident -h /var/lib/trident -s /sbin/nologin -D trident
    fi
fi
