Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/seo-sidecar / deploy-ga-update.sh |
| Date | Not specified in source |
| Repository | Janady13/seo-sidecar |
| Revision | c66ba23646cf638023e8803dc201dd69089107c9 |
| Branch | main |
| Path or archive member | deploy-ga-update.sh |
| Original SHA-256 | c61015f2d7b72910f6e9eface4e29629a753c721ca8c4c9e34baeb89bc6dcc9c |
| Git blob SHA | 57ab6e58346d27162fdcafca1edf746cc1a3cd1b |
| Reading-copy SHA-256 | d1e1baaffb49b267217880d3a3a5ba4f99d3a885d83b2827334bea39b50b5381 |
Recovered source transcript
Download complete source text ↓78 lines · 3.6 KB
Credential-bearing and unrelated personal details were removed from this reading copy. The source identity and original checksum remain recorded.
#!/bin/bash
# ─────────────────────────────────────────────────────────────────────────────
# deploy-ga-update.sh — Update sidecar with GA integration
#
# Usage: sudo bash deploy-ga-update.sh
# ─────────────────────────────────────────────────────────────────────────────
set -euo pipefail
echo "═══ SEO Sidecar GA Integration Update ═══"
# ─── Check we're running as root/sudo ───────────────────────────────────────
if [ "$EUID" -ne 0 ]; then
echo "Error: This script must be run with sudo"
exit 1
fi
# ─── Backup current sidecar ─────────────────────────────────────────────────
echo "[1/4] Backing up current sidecar..."
if [ -f /opt/seo-sidecar/sidecar.py ]; then
cp /opt/seo-sidecar/sidecar.py /opt/seo-sidecar/sidecar.py.backup-$(date +%Y%m%d-%H%M%S)
echo " ✓ Backup created"
else
echo " ⚠ No existing sidecar found"
fi
# ─── Install updated sidecar ────────────────────────────────────────────────
echo "[2/4] Installing updated sidecar with GA endpoints..."
if [ -f /tmp/sidecar.py ]; then
cp /tmp/sidecar.py /opt/seo-sidecar/sidecar.py
chown www-data:www-data /opt/seo-sidecar/sidecar.py
chmod 600 /opt/seo-sidecar/sidecar.py
echo " ✓ Sidecar updated"
else
echo " ✗ /tmp/sidecar.py not found"
echo " Copy the updated sidecar.py to /tmp first"
exit 1
fi
# ─── Restart service ────────────────────────────────────────────────────────
echo "[3/4] Restarting seo-sidecar service..."
systemctl restart seo-sidecar
sleep 2
if systemctl is-active --quiet seo-sidecar; then
echo " ✓ Service running"
else
echo " ✗ Service failed to start"
systemctl status seo-sidecar --no-pager
exit 1
fi
# ─── Test GA endpoint ───────────────────────────────────────────────────────
echo "[4/4] Testing GA endpoint..."
TOKEN=$(grep -oP 'SEO_AUTH_TOKEN=[credential removed]' /etc/systemd/system/seo-sidecar.service 2>/dev/null || echo "CHANGE_ME_DEFAULT")
GA_RESPONSE=$(curl -s -w "%{http_code}" -o /tmp/ga-test.json \
-H "Authorization: Bearer $TOKEN" \
http://127.0.0.1:9090/ga/report-latest 2>/dev/null)
if [ "$GA_RESPONSE" = "200" ]; then
echo " ✓ GA endpoint working"
GENERATED=$(cat /tmp/ga-test.json | python3 -c "import json,sys; print(json.load(sys.stdin).get('generatedAt','unknown'))" 2>/dev/null)
echo " ✓ Latest report: $GENERATED"
elif [ "$GA_RESPONSE" = "404" ]; then
echo " ⚠ GA report not found - run ga4-report-pack.py first"
else
echo " ✗ GA endpoint returned: $GA_RESPONSE"
fi
echo ""
echo "═══ Update Complete ═══"
echo ""
echo "New endpoints available:"
echo " GET /ga/report-latest - Full GA report (requires auth)"
echo " GET /ga/domain/{domain} - Single domain data"
echo " GET /ga/top-pages/{domain} - Top pages for domain"
echo ""
echo "Test: curl -H 'Authorization: Bearer $TOKEN' http://127.0.0.1:9090/ga/report-latest"