autodetect when running inside docker and provide hints

This commit is contained in:
Nick Sweeting 2020-08-10 14:15:53 -04:00
parent f24cb3dcbe
commit 33ab7fd4ec
5 changed files with 33 additions and 15 deletions

View file

@ -1,7 +1,5 @@
#!/usr/bin/env bash
COMMAND="$*"
# Autodetect UID,GID of host user based on ownership of files in the data volume
DATA_DIR="${DATA_DIR:-/data}"
ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}"
@ -18,8 +16,19 @@ if [[ "$USID" != 0 && "$GRID" != 0 ]]; then
chown "$USID":"$GRID" "$DATA_DIR/*" > /dev/null 2>&1 || true
fi
# run django as the new archivebox user
# any files touched will have the same uid,gid
# inside docker and outside docker on the host
gosu "$ARCHIVEBOX_USER" bash -c "$COMMAND"
# e.g. "archivebox server"
# Run commands as the new archivebox user in Docker.
# Any files touched will have the same uid & gid
# inside Docker and outside on the host machine.
if [[ "$1" == /* || "$1" == "echo" || "$1" == "archivebox" ]]; then
# arg 1 is a binary, execute it verbatim
# e.g. "archivebox init"
# "/bin/bash"
# "echo"
gosu "$ARCHIVEBOX_USER" bash -c "$*"
else
# no command given, assume args were meant to be passed to archivebox cmd
# e.g. "add https://example.com"
# "manage createsupseruser"
# "server 0.0.0.0:8000"
gosu "$ARCHIVEBOX_USER" bash -c "archivebox $*"
fi