2020-07-21 20:24:43 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-07-16 18:08:58 +00:00
|
|
|
|
|
|
|
DATA_DIR="${DATA_DIR:-/data}"
|
|
|
|
ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}"
|
|
|
|
|
2021-01-25 23:55:37 +00:00
|
|
|
# Set the permissions of the data dir to match the archivebox user
|
|
|
|
if [[ -d "$DATA_DIR/archive" ]]; then
|
|
|
|
# check data directory permissions
|
|
|
|
if [[ ! "$(stat -c %u $DATA_DIR/archive)" = "$(id -u archivebox)" ]]; then
|
|
|
|
echo "Change in ownership detected, please be patient while we chown existing files"
|
|
|
|
echo "This could take some time..."
|
|
|
|
chown $ARCHIVEBOX_USER:$ARCHIVEBOX_USER -R "$DATA_DIR"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# create data directory
|
|
|
|
mkdir -p "$DATA_DIR"
|
|
|
|
chown -R $ARCHIVEBOX_USER:$ARCHIVEBOX_USER "$DATA_DIR"
|
2020-07-21 17:47:21 +00:00
|
|
|
fi
|
2021-01-25 23:55:37 +00:00
|
|
|
chown $ARCHIVEBOX_USER:$ARCHIVEBOX_USER "$DATA_DIR"
|
|
|
|
|
2020-07-22 05:30:58 +00:00
|
|
|
|
2021-01-25 23:55:37 +00:00
|
|
|
# Drop permissions to run commands as the archivebox user
|
2020-08-10 18:15:53 +00:00
|
|
|
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
|