#!/usr/bin/env bash set -eo pipefail TMPDIR=$(mktemp -d) trap 'rm -rf "$TMPDIR"' EXIT BIN="/opt/google/chrome/chrome" if [ ! -f "$BIN" ]; then if [ -f "/tmp/google-chrome-stable_current_amd64.deb" ]; then >&2 echo "Using existing .deb from /tmp..." cp "/tmp/google-chrome-stable_current_amd64.deb" "$TMPDIR/chrome.deb" else >&2 echo "Fetching google-chrome-stable .deb..." curl -sSL "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" -o "$TMPDIR/chrome.deb" fi >&2 echo "Extracting binary..." ar p "$TMPDIR/chrome.deb" data.tar.xz | tar -xJ -C "$TMPDIR" ./opt/google/chrome/chrome BIN="$TMPDIR/opt/google/chrome/chrome" fi >&2 echo "Extracting keys from $BIN..." # 1. Google API Key API_KEY=$(strings "$BIN" | grep -o -E 'AIzaSy[A-Za-z0-9_-]{33}' | head -n1 || true) # 2. Main Chrome Desktop Client ID (77185425430.apps.googleusercontent.com) CLIENT_ID=$(strings "$BIN" | grep -o -E '77185425430\.apps\.googleusercontent\.com' | head -n1 || true) if [ -z "$CLIENT_ID" ]; then CLIENT_ID="77185425430.apps.googleusercontent.com" fi # 3. Main Chrome Desktop Client Secret (OTJgUOQcT7lO7GsGZq2G4IlT) CLIENT_SECRET=$(strings "$BIN" | grep -o -E 'OTJgUOQcT7lO7GsGZq2G4IlT' | head -n1 || true) if [ -z "$CLIENT_SECRET" ]; then CLIENT_SECRET="OTJgUOQcT7lO7GsGZq2G4IlT" fi if [ -z "$API_KEY" ]; then >&2 echo "Extraction failed: could not locate API_KEY." exit 1 fi EXPORTS=$(cat <&2 echo "Not root. Dumping exports to stdout:" echo "$EXPORTS" else mkdir -p /etc/chromium.d TARGET="/etc/chromium.d/sync" echo "$EXPORTS" > "$TARGET" chmod 755 "$TARGET" >&2 echo "Successfully deployed sync keys to $TARGET" fi