2020-07-21 20:24:43 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-07-16 18:08:58 +00:00
|
|
|
|
|
|
|
# detect userid:groupid of contents of data folder
|
|
|
|
DATA_DIR="${DATA_DIR:-/data}"
|
|
|
|
ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}"
|
|
|
|
|
|
|
|
# Autodetect UID and GID of host user based on ownership of files in the volume
|
|
|
|
USID=$(stat --format="%u" "$DATA_DIR")
|
|
|
|
GRID=$(stat --format="%g" "$DATA_DIR")
|
2020-07-21 20:24:43 +00:00
|
|
|
COMMAND="$*"
|
2020-07-16 18:08:58 +00:00
|
|
|
|
|
|
|
# run django as the host user's uid:gid so that any files touched have the same permissions as outside the container
|
|
|
|
# e.g. ./manage.py runserver
|
|
|
|
|
|
|
|
chown "$USID":"$GRID" "$DATA_DIR"
|
2020-07-21 17:47:21 +00:00
|
|
|
|
2020-07-21 20:14:54 +00:00
|
|
|
if [[ "$USID" != 0 && "$GRID" != 0 ]]; then
|
2020-07-21 20:24:43 +00:00
|
|
|
usermod -u "$USID" "$ARCHIVEBOX_USER"
|
|
|
|
groupmod -g "$GRID" "$ARCHIVEBOX_USER"
|
2020-07-21 20:14:54 +00:00
|
|
|
chown -R "$USID":"$GRID" "/home/$ARCHIVEBOX_USER"
|
2020-07-21 17:47:21 +00:00
|
|
|
fi
|
2020-07-21 20:24:43 +00:00
|
|
|
gosu "$ARCHIVEBOX_USER" bash -c "$COMMAND"
|