2020-07-21 20:24:43 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-07-16 18:08:58 +00:00
|
|
|
|
2020-07-22 05:30:58 +00:00
|
|
|
# Autodetect UID,GID of host user based on ownership of files in the data volume
|
2020-07-16 18:08:58 +00:00
|
|
|
DATA_DIR="${DATA_DIR:-/data}"
|
|
|
|
ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}"
|
|
|
|
|
|
|
|
USID=$(stat --format="%u" "$DATA_DIR")
|
|
|
|
GRID=$(stat --format="%g" "$DATA_DIR")
|
2020-07-21 17:47:21 +00:00
|
|
|
|
2020-07-22 05:30:58 +00:00
|
|
|
# If user is not root, modify the archivebox user+files to have the same uid,gid
|
2020-07-21 20:14:54 +00:00
|
|
|
if [[ "$USID" != 0 && "$GRID" != 0 ]]; then
|
2020-11-23 05:59:50 +00:00
|
|
|
usermod -u "$USID" "$ARCHIVEBOX_USER" > /dev/null 2>&1
|
|
|
|
groupmod -g "$GRID" "$ARCHIVEBOX_USER" > /dev/null 2>&1
|
2020-07-21 20:14:54 +00:00
|
|
|
chown -R "$USID":"$GRID" "/home/$ARCHIVEBOX_USER"
|
2020-07-28 11:57:26 +00:00
|
|
|
chown "$USID":"$GRID" "$DATA_DIR"
|
2020-07-28 11:58:16 +00:00
|
|
|
chown "$USID":"$GRID" "$DATA_DIR/*" > /dev/null 2>&1 || true
|
2020-07-21 17:47:21 +00:00
|
|
|
fi
|
2020-07-22 05:30:58 +00:00
|
|
|
|
2020-08-10 18:15:53 +00:00
|
|
|
# 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
|