#! /bin/sh

set -e

PWD_UID=$(stat . --printf="%u")

mkdir -p /src/portail/backend/media/attachments
chown -R ${PWD_UID} /src/portail/backend/media/attachments

if [ "${PWD_UID}" -ne "0" ]; then
  getent passwd ${PWD_UID} || useradd -u ${PWD_UID} -m inpnet
  [ -e /home/inpnet ] && chown ${PWD_UID} /home/inpnet
  echo "running CMD($@) for user ${PWD_UID}"
  exec su $(id -nu 1000) -c "$@"
else
  $@
fi
