docker_entrypoint.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. DATA_DIR="${DATA_DIR:-/data}"
  3. ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}"
  4. # Set the archivebox user UID & GID
  5. if [[ -n "$PUID" && "$PUID" != 0 ]]; then
  6. usermod -u "$PUID" "$ARCHIVEBOX_USER" > /dev/null 2>&1
  7. fi
  8. if [[ -n "$PGID" && "$PGID" != 0 ]]; then
  9. groupmod -g "$PGID" "$ARCHIVEBOX_USER" > /dev/null 2>&1
  10. fi
  11. # Set the permissions of the data dir to match the archivebox user
  12. if [[ -d "$DATA_DIR/archive" ]]; then
  13. # check data directory permissions
  14. if [[ ! "$(stat -c %u $DATA_DIR/archive)" = "$(id -u archivebox)" ]]; then
  15. echo "Change in ownership detected, please be patient while we chown existing files"
  16. echo "This could take some time..."
  17. chown $ARCHIVEBOX_USER:$ARCHIVEBOX_USER -R "$DATA_DIR"
  18. fi
  19. else
  20. # create data directory
  21. mkdir -p "$DATA_DIR"
  22. chown -R $ARCHIVEBOX_USER:$ARCHIVEBOX_USER "$DATA_DIR"
  23. fi
  24. chown $ARCHIVEBOX_USER:$ARCHIVEBOX_USER "$DATA_DIR"
  25. # Drop permissions to run commands as the archivebox user
  26. if [[ "$1" == /* || "$1" == "echo" || "$1" == "archivebox" ]]; then
  27. # arg 1 is a binary, execute it verbatim
  28. # e.g. "archivebox init"
  29. # "/bin/bash"
  30. # "echo"
  31. gosu "$ARCHIVEBOX_USER" bash -c "$*"
  32. else
  33. # no command given, assume args were meant to be passed to archivebox cmd
  34. # e.g. "add https://example.com"
  35. # "manage createsupseruser"
  36. # "server 0.0.0.0:8000"
  37. gosu "$ARCHIVEBOX_USER" bash -c "archivebox $*"
  38. fi