From c4a3a45bf7e542086b59c5767a3c67993e0654d6 Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Mon, 17 Mar 2025 15:35:09 +0000 Subject: [PATCH] Script to auto-generate a service account --- .gitignore | 1 + scripts/generate_google_services.sh | 115 ++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 scripts/generate_google_services.sh diff --git a/.gitignore b/.gitignore index 72d8531..704947b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ temp/ .DS_Store expmt/ service_account.json +service_account-*.json __pycache__/ ._* anu.html diff --git a/scripts/generate_google_services.sh b/scripts/generate_google_services.sh new file mode 100644 index 0000000..2668fd3 --- /dev/null +++ b/scripts/generate_google_services.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash + +set -e # Exit on error + + +UUID=$(LC_ALL=C tr -dc a-z0-9 /dev/null; then + echo "✅ Google Cloud SDK is already installed" + return 0 + fi + + echo "📦 Installing Google Cloud SDK..." + + # Detect OS + case "$(uname -s)" in + Darwin*) + if command -v brew &> /dev/null; then + echo "🍺 Installing via Homebrew..." + brew install google-cloud-sdk --cask + else + echo "📥 Downloading Google Cloud SDK for macOS..." + curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-latest-darwin-x86_64.tar.gz + tar -xf google-cloud-cli-latest-darwin-x86_64.tar.gz + ./google-cloud-sdk/install.sh --quiet + rm google-cloud-cli-latest-darwin-x86_64.tar.gz + echo "🔄 Please restart your terminal and run this script again" + exit 0 + fi + ;; + Linux*) + echo "📥 Downloading Google Cloud SDK for Linux..." + curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-latest-linux-x86_64.tar.gz + tar -xf google-cloud-cli-latest-linux-x86_64.tar.gz + ./google-cloud-sdk/install.sh --quiet + rm google-cloud-cli-latest-linux-x86_64.tar.gz + echo "🔄 Please restart your terminal and run this script again" + exit 0 + ;; + CYGWIN*|MINGW*|MSYS*) + echo "⚠️ Windows detected. Please follow manual installation instructions at:" + echo "https://cloud.google.com/sdk/docs/install-sdk" + exit 1 + ;; + *) + echo "⚠️ Unknown operating system. Please follow manual installation instructions at:" + echo "https://cloud.google.com/sdk/docs/install-sdk" + exit 1 + ;; + esac + + echo "✅ Google Cloud SDK installed" +} + +# Install Google Cloud SDK if needed +install_gcloud_sdk + +# Login to Google Cloud +if gcloud auth list --filter=status:ACTIVE --format="value(account)" | grep -q "@"; then + echo "✅ Already authenticated with Google Cloud" +else + echo "🔑 Authenticating with Google Cloud..." + gcloud auth login +fi + +# Create project +echo "🌟 Creating Google Cloud project: $PROJECT_NAME" +gcloud projects create $PROJECT_NAME + +# Create service account +echo "👤 Creating service account: $ACCOUNT_NAME" +gcloud iam service-accounts create $ACCOUNT_NAME --project $PROJECT_NAME + +# Get the service account email +echo "📧 Retrieving service account email..." +ACCOUNT_EMAIL=$(gcloud iam service-accounts list --project $PROJECT_NAME --format="value(email)") + +# Create and download key +echo "🔑 Generating service account key file: $KEY_FILE" +gcloud iam service-accounts keys create $KEY_FILE --iam-account=$ACCOUNT_EMAIL + +# Enable required APIs (uncomment and add APIs as needed) +echo "⬆️ Enabling required Google APIs..." +gcloud services enable sheets.googleapis.com --project $PROJECT_NAME +gcloud services enable drive.googleapis.com --project $PROJECT_NAME + +echo "=====================================================" +echo "✅ SETUP COMPLETE!" +echo "=====================================================" +echo "📝 Important Information:" +echo " • Project Name: $PROJECT_NAME" +echo " • Service Account: $ACCOUNT_EMAIL" +echo " • Key File: $KEY_FILE" +echo "" +echo "📋 Next Steps:" +echo " 1. Share any Google Sheets with this email address:" +echo " $ACCOUNT_EMAIL" +echo " 2. Move $KEY_FILE to your auto-archiver secrets directory" +echo " 3. Update your auto-archiver config to use this key file (if needed)" +echo "=====================================================" \ No newline at end of file