2023-08-22 19:35:43 -04:00
|
|
|
#!/bin/bash
|
2020-07-16 14:08:58 -04:00
|
|
|
|
|
|
|
DATA_DIR="${DATA_DIR:-/data}"
|
|
|
|
ARCHIVEBOX_USER="${ARCHIVEBOX_USER:-archivebox}"
|
|
|
|
|
2021-02-16 01:22:36 -05:00
|
|
|
|
2021-01-28 09:37:15 -05:00
|
|
|
# Set the archivebox user UID & GID
|
2021-01-28 09:48:21 -05:00
|
|
|
if [[ -n "$PUID" && "$PUID" != 0 ]]; then
|
|
|
|
usermod -u "$PUID" "$ARCHIVEBOX_USER" > /dev/null 2>&1
|
2021-01-28 09:37:15 -05:00
|
|
|
fi
|
2021-01-28 09:48:21 -05:00
|
|
|
if [[ -n "$PGID" && "$PGID" != 0 ]]; then
|
|
|
|
groupmod -g "$PGID" "$ARCHIVEBOX_USER" > /dev/null 2>&1
|
2021-01-28 09:37:15 -05:00
|
|
|
fi
|
|
|
|
|
2023-10-18 21:24:43 -04:00
|
|
|
PUID="$(id -u archivebox)"
|
|
|
|
PGID="$(id -g archivebox)"
|
2021-02-16 01:22:36 -05:00
|
|
|
|
2023-10-18 21:24:43 -04:00
|
|
|
# Check the permissions of the data dir (or create if it doesn't exist)
|
2021-01-25 18:55:37 -05:00
|
|
|
if [[ -d "$DATA_DIR/archive" ]]; then
|
2023-10-18 21:24:43 -04:00
|
|
|
if touch "$DATA_DIR/archive/.permissions_test_safe_to_delete"; then
|
|
|
|
# It's fine, we are able to write to the data directory
|
|
|
|
rm "$DATA_DIR/archive/.permissions_test_safe_to_delete"
|
|
|
|
# echo "[√] Permissions are correct"
|
|
|
|
else
|
|
|
|
echo "[X] Permissions Error: ArchiveBox is not able to write to your data dir. You need to fix the data dir ownership and retry:" >2
|
|
|
|
echo " chown -R $PUID:$PGID data" >2
|
|
|
|
echo " https://docs.linuxserver.io/general/understanding-puid-and-pgid" >2
|
|
|
|
exit 1
|
2021-01-25 18:55:37 -05:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
# create data directory
|
2021-03-27 05:28:54 -04:00
|
|
|
mkdir -p "$DATA_DIR/logs"
|
2020-07-21 13:47:21 -04:00
|
|
|
fi
|
2023-10-18 21:24:43 -04:00
|
|
|
chown $ARCHIVEBOX_USER:$ARCHIVEBOX_USER "$DATA_DIR" "$DATA_DIR"/*
|
2021-01-25 18:55:37 -05:00
|
|
|
|
2020-07-22 01:30:58 -04:00
|
|
|
|
2021-01-25 18:55:37 -05:00
|
|
|
# Drop permissions to run commands as the archivebox user
|
2020-08-10 14:15:53 -04:00
|
|
|
if [[ "$1" == /* || "$1" == "echo" || "$1" == "archivebox" ]]; then
|
|
|
|
# arg 1 is a binary, execute it verbatim
|
|
|
|
# e.g. "archivebox init"
|
|
|
|
# "/bin/bash"
|
|
|
|
# "echo"
|
2021-02-16 01:22:36 -05:00
|
|
|
exec gosu "$ARCHIVEBOX_USER" bash -c "$*"
|
2020-08-10 14:15:53 -04:00
|
|
|
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"
|
2021-02-16 01:22:36 -05:00
|
|
|
exec gosu "$ARCHIVEBOX_USER" bash -c "archivebox $*"
|
2020-08-10 14:15:53 -04:00
|
|
|
fi
|