diff --git a/archivebox/tests/test_setup_script.py b/archivebox/tests/test_setup_script.py index 04a56cd4..3911d7b3 100644 --- a/archivebox/tests/test_setup_script.py +++ b/archivebox/tests/test_setup_script.py @@ -21,6 +21,13 @@ def test_setup_script_never_recursively_chowns_collection_data(): assert "chown -R" not in "\n".join(line for line in script.splitlines() if "archivebox/data" in line) +def test_setup_script_gives_archivebox_user_ownership_of_runtime_parent_dirs(): + script = SETUP_SCRIPT.read_text() + + assert 'for path in "$HOME/.local" "$HOME/.local/share" "$HOME/.cache" "$HOME/.cache/archivebox"; do' in script + assert 'chown "$ARCHIVEBOX_SYSTEM_UID:$ARCHIVEBOX_SYSTEM_GID" "$path"' in script + + def test_setup_script_bootstraps_locked_abxpkg_version(): script = SETUP_SCRIPT.read_text() diff --git a/bin/setup.sh b/bin/setup.sh index 826793f8..5bbd06e5 100755 --- a/bin/setup.sh +++ b/bin/setup.sh @@ -102,6 +102,13 @@ fix_root_install_ownership() { return 0 fi + # Keep shared runtime parents writable after ArchiveBox drops privileges. + for path in "$HOME/.local" "$HOME/.local/share" "$HOME/.cache" "$HOME/.cache/archivebox"; do + if [ -e "$path" ]; then + chown "$ARCHIVEBOX_SYSTEM_UID:$ARCHIVEBOX_SYSTEM_GID" "$path" + fi + done + for path in "$HOME/.local/bin" "$HOME/.local/share/uv" "$HOME/.cache/uv" "$ABXPKG_LIB_DIR"; do if [ -e "$path" ]; then chown -R "$ARCHIVEBOX_SYSTEM_UID:$ARCHIVEBOX_SYSTEM_GID" "$path"