#!/bin/bash

# Make sure scanner user and groups have always same UID:GID in the container
GROUPID=10000
USERID=10000
USERNAME=scanner
GROUPNAME=scanner
HOMEDIR=/home/scanner

if getent group $GROUPNAME >/dev/null; then
    groupmod -g $GROUPID $GROUPNAME
else
    groupadd -r -g $GROUPID $GROUPNAME
fi

if getent passwd $USERNAME >/dev/null; then
    usermod -u $USERID $USERNAME
    chown -R $USERNAME:$GROUPNAME $HOMEDIR
else
    useradd -r -g $GROUPNAME -d $HOMEDIR -s /sbin/nologin -m -l -c "user for Trivy" -u $USERID $USERNAME
fi

