docker-entrypoint.sh 1022 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. set -x
  3. # Get the PUID and PGID from environment variables (or use default values 1000 if not set)
  4. PUID=${PUID:-1000}
  5. PGID=${PGID:-1000}
  6. # Check if the provided PUID and PGID are non-empty, numeric values; otherwise, assign default values.
  7. if ! [[ "$PUID" =~ ^[0-9]+$ ]]; then
  8. PUID=1000
  9. fi
  10. if ! [[ "$PGID" =~ ^[0-9]+$ ]]; then
  11. PGID=1000
  12. fi
  13. # Check if the specified group with PGID exists, if not, create it.
  14. if ! getent group "$PGID" >/dev/null; then
  15. groupadd -g "$PGID" appgroup
  16. fi
  17. # Create user.
  18. useradd --create-home --shell /bin/bash --uid "$PUID" --gid "$PGID" appuser
  19. # Make user the owner of the app directory.
  20. chown -R appuser:appgroup /app
  21. # Set permissions on font directories.
  22. if [ -d "/usr/share/fonts" ]; then
  23. chmod -R 777 /usr/share/fonts
  24. fi
  25. if [ -d "/var/cache/fontconfig" ]; then
  26. chmod -R 777 /var/cache/fontconfig
  27. fi
  28. if [ -d "/usr/local/share/fonts" ]; then
  29. chmod -R 777 /usr/local/share/fonts
  30. fi
  31. # Execute the application per the arguments to the file.
  32. exec su appuser -p -c "$@"