#!/bin/sh

# OpenShift containers run as a user with a random uid. That uid does not appear
# in /etc/passwd, causing any attempts to look up the username associated with
# that uid to fail. This script appends an entry to /etc/passwd for the
# "default" user, using the current uid and gid.

if ! whoami &> /dev/null; then
  if [ -w /etc/passwd ]; then
    echo "${USER_NAME:-default}:x:$(id -u):$(id -g):${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd
  fi
fi

exec "$@"
