2020-07-21 16:24:43 -04:00
|
|
|
#!/usr/bin/env bash
|
2020-07-16 14:08:58 -04:00
|
|
|
|
2020-07-22 01:30:58 -04:00
|
|
|
COMMAND="$*"
|
|
|
|
|
|
|
|
# Autodetect UID,GID of host user based on ownership of files in the data volume
|
2020-07-16 14:08:58 -04: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 13:47:21 -04:00
|
|
|
|
2020-07-22 01:30:58 -04:00
|
|
|
# If user is not root, modify the archivebox user+files to have the same uid,gid
|
2020-07-21 16:14:54 -04:00
|
|
|
if [[ "$USID" != 0 && "$GRID" != 0 ]]; then
|
2020-07-22 01:30:58 -04:00
|
|
|
chown "$USID":"$GRID" "$DATA_DIR"
|
2020-07-21 16:24:43 -04:00
|
|
|
usermod -u "$USID" "$ARCHIVEBOX_USER"
|
|
|
|
groupmod -g "$GRID" "$ARCHIVEBOX_USER"
|
2020-07-21 16:14:54 -04:00
|
|
|
chown -R "$USID":"$GRID" "/home/$ARCHIVEBOX_USER"
|
2020-07-21 13:47:21 -04:00
|
|
|
fi
|
2020-07-22 01:30:58 -04:00
|
|
|
|
|
|
|
# run django as the new archivebox user
|
|
|
|
# any files touched will have the same uid,gid
|
|
|
|
# inside docker and outside docker on the host
|
2020-07-21 16:24:43 -04:00
|
|
|
gosu "$ARCHIVEBOX_USER" bash -c "$COMMAND"
|
2020-07-22 01:30:58 -04:00
|
|
|
# e.g. "archivebox server"
|