#!/usr/bin/env bash # # linkedin-session adapter wrapper # # Called by /cheat-retro when state.data_collection=adapter and platform=linkedin. # # Usage: # bash run.sh [] # # Example: # bash run.sh 7470493738918920193 ~/my-channel/videos/2026-05-04_7470493738918920193_post # bash run.sh https://www.linkedin.com/feed/update/urn:li:activity:7470493738918920193/ # # Output: writes report.md INTO the video_folder. # Exit codes: # 0 = success (report.md written) # 1 = login expired or required (no .auth-linkedin/) # 2 = adapter dependency missing (playwright not installed) # 3 = other failure (network, parse error, bad activity id, etc.) set -uo pipefail ACTIVITY_ID="${1:-}" VIDEO_FOLDER="${2:-}" SCRIPT_PATH="${3:-}" if [[ -z "$ACTIVITY_ID" || -z "$VIDEO_FOLDER" ]]; then echo "Usage: bash run.sh []" >&2 exit 3 fi # Resolve adapter source dir (where this script lives) ADAPTER_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # Find Python — prefer venv in user's project root if exists PYTHON="" PROJECT_ROOT="$( dirname "$( dirname "$( realpath "$VIDEO_FOLDER" )" )" )" if [[ -x "$PROJECT_ROOT/.venv/bin/python" ]]; then PYTHON="$PROJECT_ROOT/.venv/bin/python" elif command -v python3 >/dev/null 2>&1; then PYTHON="python3" elif command -v python >/dev/null 2>&1; then PYTHON="python" else echo "❌ python not found — install Python 3.10+ first" >&2 exit 2 fi # Verify playwright is installed if ! "$PYTHON" -c "import playwright" 2>/dev/null; then cat >&2 <&2 </report.md. # Move it into our canonical video_folder if names differ. LATEST_REPORT=$(find "$( dirname "$VIDEO_FOLDER" )" -name "report.md" -newer "$VIDEO_FOLDER" -type f 2>/dev/null | head -1) if [[ -n "$LATEST_REPORT" && "$( dirname "$LATEST_REPORT" )" != "$VIDEO_FOLDER" ]]; then cp "$LATEST_REPORT" "$VIDEO_FOLDER/report.md" AUTO_DIR=$( dirname "$LATEST_REPORT" ) if [[ -f "$AUTO_DIR/script.txt" ]]; then cp "$AUTO_DIR/script.txt" "$VIDEO_FOLDER/script.txt" fi echo "[linkedin-session] moved auto-named output to $VIDEO_FOLDER/" fi if [[ ! -f "$VIDEO_FOLDER/report.md" ]]; then echo "❌ report.md not produced — see review.py output above for details" >&2 exit 3 fi echo "✅ report.md written to $VIDEO_FOLDER/report.md" exit 0