- Add Next.js app structure with base configs, linting, and formatting - Implement LiveKit Meet page, types, and utility functions - Add Docker, Compose, and deployment scripts for backend and token server - Provide E2E and smoke test scaffolding with Puppeteer and Playwright helpers - Include CSS modules and global styles for UI - Add postMessage and studio integration utilities - Update package.json with dependencies and scripts for development and testing
95 lines
3.4 KiB
Bash
95 lines
3.4 KiB
Bash
#!/usr/bin/env bash
|
|
# scripts/update_backend_env.sh
|
|
# Safely update LIVEKIT_API_KEY and LIVEKIT_API_SECRET in backend-api .env and restart the service (docker-compose or systemd).
|
|
# Usage:
|
|
# ./scripts/update_backend_env.sh --env-file /path/to/packages/backend-api/.env --compose-file /path/to/deploy/docker-compose.token.yml --service backend-api --livekit-key KEY --livekit-secret SECRET
|
|
|
|
set -euo pipefail
|
|
show_usage(){
|
|
cat <<EOF
|
|
Usage: $0 --env-file PATH --compose-file PATH --service NAME --livekit-key KEY --livekit-secret SECRET
|
|
This will backup the env file, update LIVEKIT_API_KEY and LIVEKIT_API_SECRET, and restart the backend service.
|
|
If you run on a systemd service instead of docker-compose omit --compose-file and provide --systemd-service <name>.
|
|
EOF
|
|
}
|
|
|
|
ENV_FILE=""
|
|
COMPOSE_FILE=""
|
|
SERVICE_NAME="backend-api"
|
|
SYSTEMD_SERVICE=""
|
|
LIVEKIT_KEY=""
|
|
LIVEKIT_SECRET=""
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--env-file) ENV_FILE="$2"; shift 2;;
|
|
--compose-file) COMPOSE_FILE="$2"; shift 2;;
|
|
--service) SERVICE_NAME="$2"; shift 2;;
|
|
--systemd-service) SYSTEMD_SERVICE="$2"; shift 2;;
|
|
--livekit-key) LIVEKIT_KEY="$2"; shift 2;;
|
|
--livekit-secret) LIVEKIT_SECRET="$2"; shift 2;;
|
|
-h|--help) show_usage; exit 0;;
|
|
*) echo "Unknown arg $1"; show_usage; exit 2;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$ENV_FILE" || -z "$LIVEKIT_KEY" || -z "$LIVEKIT_SECRET" ]]; then
|
|
echo "ERROR: missing required arguments" >&2
|
|
show_usage
|
|
exit 2
|
|
fi
|
|
if [[ ! -f "$ENV_FILE" ]]; then
|
|
echo "ERROR: env file not found: $ENV_FILE" >&2
|
|
exit 2
|
|
fi
|
|
|
|
BACKUP="${ENV_FILE}.bak.$(date +%Y%m%d%H%M%S)"
|
|
cp "$ENV_FILE" "$BACKUP"
|
|
echo "Backed up $ENV_FILE -> $BACKUP"
|
|
|
|
# Replace or add keys
|
|
# Use sed to support entries with or without quotes
|
|
if grep -q '^LIVEKIT_API_KEY=' "$ENV_FILE"; then
|
|
sed -i "s|^LIVEKIT_API_KEY=.*$|LIVEKIT_API_KEY=${LIVEKIT_KEY}|" "$ENV_FILE"
|
|
else
|
|
echo "LIVEKIT_API_KEY=${LIVEKIT_KEY}" >> "$ENV_FILE"
|
|
fi
|
|
|
|
if grep -q '^LIVEKIT_API_SECRET=' "$ENV_FILE"; then
|
|
sed -i "s|^LIVEKIT_API_SECRET=.*$|LIVEKIT_API_SECRET=${LIVEKIT_SECRET}|" "$ENV_FILE"
|
|
else
|
|
echo "LIVEKIT_API_SECRET=${LIVEKIT_SECRET}" >> "$ENV_FILE"
|
|
fi
|
|
|
|
echo "Updated LIVEKIT_API_KEY and LIVEKIT_API_SECRET in $ENV_FILE"
|
|
|
|
# Restart logic
|
|
if [[ -n "$COMPOSE_FILE" && -f "$COMPOSE_FILE" ]]; then
|
|
echo "Restarting service $SERVICE_NAME using docker compose file $COMPOSE_FILE"
|
|
if command -v docker-compose >/dev/null 2>&1; then
|
|
docker-compose -f "$COMPOSE_FILE" up -d --no-deps --force-recreate "$SERVICE_NAME"
|
|
elif command -v docker >/dev/null 2>&1 && docker compose version >/dev/null 2>&1; then
|
|
docker compose -f "$COMPOSE_FILE" up -d --no-deps --force-recreate "$SERVICE_NAME"
|
|
else
|
|
echo "ERROR: docker compose not found. Please restart the service manually." >&2
|
|
exit 2
|
|
fi
|
|
echo "Service recreated via docker compose. Waiting 5s..."
|
|
sleep 5
|
|
elif [[ -n "$SYSTEMD_SERVICE" ]]; then
|
|
echo "Restarting systemd service: $SYSTEMD_SERVICE"
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl restart "$SYSTEMD_SERVICE"
|
|
echo "Waiting 5s for service to be ready..."
|
|
sleep 5
|
|
else
|
|
echo "No restart command provided (no --compose-file or --systemd-service). Remember to restart backend service manually."
|
|
fi
|
|
|
|
echo "Done. Run verification script to confirm tokens and LiveKit connectivity."
|
|
|
|
echo "Suggested verification (local): ./scripts/verify_backend_after_update.sh --session-room e2e_room --session-user e2e_test --backend-url http://localhost:4000"
|
|
|
|
exit 0
|
|
|