#!/usr/bin/env bash # Show API key and step-by-step browser instructions for Server UI. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" STACK_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" REPO_ROOT="$(cd "${STACK_DIR}/../.." && pwd)" PROD_ENV="/opt/control-plane/.env" DEV_ENV="${REPO_ROOT}/stacks/control-plane/.env" UI_PORT=8091 # Production is canonical when installed; dev only as fallback. if [[ -f "${PROD_ENV}" ]]; then ENV_FILE="${PROD_ENV}" UI_PORT="$(grep '^SERVER_UI_PORT=' "${PROD_ENV}" 2>/dev/null | cut -d= -f2- || true)" if [[ -z "${UI_PORT}" ]]; then UI_PORT="$(sudo grep '^SERVER_UI_PORT=' "${PROD_ENV}" 2>/dev/null | cut -d= -f2- || true)" fi elif [[ -r "${DEV_ENV}" ]]; then ENV_FILE="${DEV_ENV}" UI_PORT="$(grep '^SERVER_UI_PORT=' "${DEV_ENV}" 2>/dev/null | cut -d= -f2- || echo 8091)" else ENV_FILE="${PROD_ENV}" fi [[ -n "${UI_PORT}" ]] || UI_PORT=8091 # shellcheck source=print-api-key-instructions.sh source "${SCRIPT_DIR}/print-api-key-instructions.sh" if ! print_api_key_instructions "${ENV_FILE}" "${UI_PORT}" "${DEV_ENV}"; then if [[ -r "${DEV_ENV}" && "${ENV_FILE}" != "${DEV_ENV}" ]]; then echo "Fallback: odczyt z dev (prod nieczytelny bez sudo): ${DEV_ENV}" print_api_key_instructions "${DEV_ENV}" "${UI_PORT}" "" else exit 1 fi fi