Skip to content

Commit d6d5a08

Browse files
committed
Allow user to save downloaded keyfile to a different folder
1 parent 4886750 commit d6d5a08

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

Diff for: docs/source/how_to/gsheets_setup.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ To do this, you can either:
1515
* a) follow the steps in [this guide](https://gspread.readthedocs.io/en/latest/oauth2.html) all the way up until step 8. You should have downloaded a file called `service_account.json` and should save it in the `secrets/` folder
1616
* b) run the following script to automatically generate the file:
1717
```{code} bash
18-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/bellingcat/auto-archiver/refs/heads/main/scripts/generate_google_services.sh)"
18+
https://raw.githubusercontent.com/bellingcat/auto-archiver/refs/heads/main/scripts/generate_google_services.sh | bash -s --
1919
```
2020
This uses gcloud to create a new project, a new user and downloads the service account automatically for you. The service account file will have the name `service_account-XXXXXXX.json` where XXXXXXX is a random 16 letter/digit string for the project created.
2121

22+
```{note}
23+
To save the generated file to a different folder, pass an argument as follows:
24+
```{code} bash
25+
https://raw.githubusercontent.com/bellingcat/auto-archiver/refs/heads/main/scripts/generate_google_services.sh | bash -s -- /path/to/secrets
26+
```
27+
28+
----------
29+
2230
Once you've downloaded the file, you can save it to `secrets/service_account.json` (the default name), or to another file and then change the location in the settings (see step 4).
2331

2432
Also make sure to **note down** the email address for this service account. You'll need that for step 3.

Diff for: scripts/generate_google_services.sh

+24-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ UUID=$(LC_ALL=C tr -dc a-z0-9 </dev/urandom | head -c 16)
77
PROJECT_NAME="auto-archiver-$UUID"
88
ACCOUNT_NAME="autoarchiver"
99
KEY_FILE="service_account-$UUID.json"
10+
DEST_DIR="$1"
1011

1112
echo "====================================================="
1213
echo "🔧 Auto-Archiver Google Services Setup Script"
@@ -16,6 +17,9 @@ echo " 1. Install Google Cloud SDK if needed"
1617
echo " 2. Create a Google Cloud project named $PROJECT_NAME"
1718
echo " 3. Create a service account for Auto-Archiver"
1819
echo " 4. Generate a key file for API access"
20+
echo ""
21+
echo " Tip: Pass a directory path as an argument to this script to move the key file there"
22+
echo " e.g. ./generate_google_services.sh /path/to/secrets"
1923
echo "====================================================="
2024

2125
# Check and install Google Cloud SDK based on platform
@@ -86,6 +90,11 @@ gcloud projects create $PROJECT_NAME
8690
echo "👤 Creating service account: $ACCOUNT_NAME"
8791
gcloud iam service-accounts create $ACCOUNT_NAME --project $PROJECT_NAME
8892

93+
# Enable required APIs (uncomment and add APIs as needed)
94+
echo "⬆️ Enabling required Google APIs..."
95+
gcloud services enable sheets.googleapis.com --project $PROJECT_NAME
96+
gcloud services enable drive.googleapis.com --project $PROJECT_NAME
97+
8998
# Get the service account email
9099
echo "📧 Retrieving service account email..."
91100
ACCOUNT_EMAIL=$(gcloud iam service-accounts list --project $PROJECT_NAME --format="value(email)")
@@ -94,10 +103,21 @@ ACCOUNT_EMAIL=$(gcloud iam service-accounts list --project $PROJECT_NAME --forma
94103
echo "🔑 Generating service account key file: $KEY_FILE"
95104
gcloud iam service-accounts keys create $KEY_FILE --iam-account=$ACCOUNT_EMAIL
96105

97-
# Enable required APIs (uncomment and add APIs as needed)
98-
echo "⬆️ Enabling required Google APIs..."
99-
gcloud services enable sheets.googleapis.com --project $PROJECT_NAME
100-
gcloud services enable drive.googleapis.com --project $PROJECT_NAME
106+
# move the file to TARGET_DIR if provided
107+
if [[ -n "$DEST_DIR" ]]; then
108+
# Expand `~` if used
109+
DEST_DIR=$(eval echo "$DEST_DIR")
110+
111+
# Ensure the directory exists
112+
if [[ ! -d "$DEST_DIR" ]]; then
113+
mkdir -p "$DEST_DIR"
114+
fi
115+
116+
DEST_PATH="$DEST_DIR/$KEY_FILE"
117+
echo "🚚 Moving key file to: $DEST_PATH"
118+
mv "$KEY_FILE" "$DEST_PATH"
119+
KEY_FILE="$DEST_PATH"
120+
fi
101121

102122
echo "====================================================="
103123
echo "✅ SETUP COMPLETE!"

0 commit comments

Comments
 (0)