Files
waters-boards/deploy/aws/set-google-client-id.sh
michaelandClaude Fable 5.1 2a5ad98250
Deploy Waters Boards to AWS / deploy (push) Canceled after 0s
Add set-google-client-id.sh for the AWS box
Prompts for the OAuth client ID, writes it to /opt/waters-boards/.env,
recreates the app container and prints the sign-in config it reports.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-14 14:33:48 -04:00

47 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Put the Google OAuth client ID into the box's .env and recreate the app container.
#
# Usage, from the repo root:
# deploy/aws/set-google-client-id.sh # prompts for the ID
# deploy/aws/set-google-client-id.sh <client-id>
#
# Target host comes from BOARDS_HOST (default: the "boards-aws" SSH alias). Only the
# GOOGLE_CLIENT_ID line in /opt/waters-boards/.env is changed. A container restart is not
# enough for an env_file change, so the app container is recreated (data/ is untouched).
set -euo pipefail
HOST="${BOARDS_HOST:-boards-aws}"
REMOTE_DIR=/opt/waters-boards
SSH=(ssh -o BatchMode=yes "$HOST")
ID="${1:-}"
if [ -z "$ID" ]; then
printf 'Paste the Google OAuth client ID (ends in .apps.googleusercontent.com): '
read -r ID
fi
ID="${ID//[[:space:]]/}"
case "$ID" in
*.apps.googleusercontent.com) ;;
*) echo "That doesn't look like a Google client ID: '$ID'" >&2; exit 1 ;;
esac
echo "==> Writing GOOGLE_CLIENT_ID to $HOST:$REMOTE_DIR/.env"
"${SSH[@]}" "sed -i 's|^GOOGLE_CLIENT_ID=.*|GOOGLE_CLIENT_ID=$ID|' $REMOTE_DIR/.env && grep -q '^GOOGLE_CLIENT_ID=$ID\$' $REMOTE_DIR/.env" \
|| { echo "ABORT: could not set GOOGLE_CLIENT_ID in $REMOTE_DIR/.env (is the line present?)" >&2; exit 1; }
echo "==> Recreating the app container so it reads the new .env"
"${SSH[@]}" "cd $REMOTE_DIR && docker compose up -d boards"
echo "==> Waiting for it to report healthy"
for i in $(seq 1 20); do
s=$("${SSH[@]}" "docker inspect --format '{{.State.Health.Status}}' waters-boards" 2>/dev/null || echo starting)
[ "$s" = healthy ] && break
sleep 3
done
echo " $s"
echo "==> Sign-in config the server now reports (googleClientId should be set):"
"${SSH[@]}" "docker exec waters-boards wget -qO- http://127.0.0.1:3100/api/auth/config"
echo