#!/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 # # 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