#!/usr/bin/bash

# run this php command as correct user to fix permission issues in docker exec
# docker exec does run as root by default

NGINX_USERNAME=$(stat -L -c %U /framelix/userdata/)
CURRENT_USERNAME=$(whoami)

if [ "$NGINX_USERNAME" != "$CURRENT_USERNAME" ]; then
  su $NGINX_USERNAME -s /usr/bin/php  -- "$@"
else
  /usr/bin/php "$@"
fi