#!/bin/bash

#======================================
# Functions...
#--------------------------------------
test -f /.kconfig && . /.kconfig
test -f /.profile && . /.profile

#======================================
# Greeting...
#--------------------------------------
echo "Configure image: [$kiwi_iname]..."

#======================================
# Remove locale files
#--------------------------------------
(cd /usr/share/locale && find -name '*.mo' | xargs rm)

# Make sure registry user and groups have always same UID:GID in the container
# The UID and GID must not conflict with the ones for the harbor user/group
GROUPID=10001
USERID=10001
USERNAME=registry
GROUPNAME=registry
HOMEDIR=/var/lib/registry

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 Docker registry" -u $USERID $USERNAME
fi


exit 0
