Skip to content

Commit 34cb7f4

Browse files
committed
Ensure Playwright browsers installed for target user and fix cache ownership
1 parent 2bde88d commit 34cb7f4

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

scripts/setup_vm.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,19 @@ chmod +x "$REPO_DIR"/scripts/*.sh || true
3434
echo "Creating virtualenv and installing python deps as $USER_NAME..."
3535
su - "$USER_NAME" -c "bash -lc 'cd \"$REPO_DIR\" && python3 -m venv .venv && . .venv/bin/activate && python -m pip install --upgrade pip setuptools wheel && pip install -r requirements.txt'"
3636

37-
# Install Playwright browsers (run as root to allow package installs)
37+
# Install Playwright browsers (run as root first to ensure system deps, then as the user to populate user's cache)
3838
echo "Installing Playwright browsers (this can take a while)..."
39-
# Run inside the venv as root so playwright can install system deps without prompting for password
40-
bash -lc "cd \"$REPO_DIR\" && . .venv/bin/activate && python -m playwright install --with-deps --force"
41-
# If you prefer to run as the target user (no root), uncomment the following line instead:
42-
# su - "$USER_NAME" -c "bash -lc 'cd \"$REPO_DIR\" && . .venv/bin/activate && python -m playwright install --with-deps --force'"
39+
# 1) Run as root inside the venv so playwright can install system deps without prompting for password
40+
bash -lc "cd \"$REPO_DIR\" && . .venv/bin/activate && python -m playwright install --with-deps --force" || true
41+
42+
# 2) Ensure the target user has the browser binaries installed in their own cache
43+
echo "Ensuring Playwright browsers are available for $USER_NAME (installing as that user)..."
44+
su - "$USER_NAME" -c "bash -lc 'cd \"$REPO_DIR\" && . .venv/bin/activate && python -m playwright install --force'" || true
45+
46+
# 3) Fix permissions of the user's playwright cache directory if it exists
47+
if [ -d "/home/$USER_NAME/.cache/ms-playwright" ]; then
48+
chown -R "$USER_NAME":"$USER_NAME" "/home/$USER_NAME/.cache/ms-playwright" || true
49+
fi
4350

4451
echo "Setup complete. You can now run:"
4552
echo " sudo -u $USER_NAME -i bash -lc 'cd $REPO_DIR && ./scripts/run_download.sh --url <URL> --max-pages 5'"

0 commit comments

Comments
 (0)