1
0
Fork 0

Replace chown of entire data directory when ownership mismatch detected

This commit is contained in:
Nick Sweeting 2023-10-18 18:24:43 -07:00 committed by GitHub
parent e9c85aa812
commit 4f655fc4a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,21 +12,26 @@ if [[ -n "$PGID" && "$PGID" != 0 ]]; then
groupmod -g "$PGID" "$ARCHIVEBOX_USER" > /dev/null 2>&1 groupmod -g "$PGID" "$ARCHIVEBOX_USER" > /dev/null 2>&1
fi fi
PUID="$(id -u archivebox)"
PGID="$(id -g archivebox)"
# Set the permissions of the data dir to match the archivebox user # Check the permissions of the data dir (or create if it doesn't exist)
if [[ -d "$DATA_DIR/archive" ]]; then if [[ -d "$DATA_DIR/archive" ]]; then
# check data directory permissions if touch "$DATA_DIR/archive/.permissions_test_safe_to_delete"; then
if [[ ! "$(stat -c %u $DATA_DIR/archive)" = "$(id -u archivebox)" ]]; then # It's fine, we are able to write to the data directory
echo "Change in ownership detected, please be patient while we chown existing files" rm "$DATA_DIR/archive/.permissions_test_safe_to_delete"
echo "This could take some time..." # echo "[√] Permissions are correct"
chown $ARCHIVEBOX_USER:$ARCHIVEBOX_USER -R "$DATA_DIR" 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
fi fi
else else
# create data directory # create data directory
mkdir -p "$DATA_DIR/logs" mkdir -p "$DATA_DIR/logs"
chown -R $ARCHIVEBOX_USER:$ARCHIVEBOX_USER "$DATA_DIR"
fi fi
chown $ARCHIVEBOX_USER:$ARCHIVEBOX_USER "$DATA_DIR" chown $ARCHIVEBOX_USER:$ARCHIVEBOX_USER "$DATA_DIR" "$DATA_DIR"/*
# Drop permissions to run commands as the archivebox user # Drop permissions to run commands as the archivebox user