#!/bin/bash # AITBC Messaging Authentication Configuration Script # Sets up messaging service authentication for agent training # # DEPRECATED: This script is deprecated in favor of the Python-based setup system. # Use: python -m aitbc.training_setup.cli setup (includes messaging configuration) # See: /opt/aitbc/docs/agent-training/ENVIRONMENT_SETUP.md set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" AITBC_DIR="/opt/aitbc" LOG_DIR="/var/log/aitbc/training-setup" mkdir -p "$LOG_DIR" # Configuration MESSAGING_SERVICE_PORT=9002 AUTH_TOKEN_FILE="/var/lib/aitbc/messaging-auth.token" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' log() { local level="$1" shift local message="$@" local timestamp=$(date -Iseconds) echo -e "${timestamp} [${level}] ${message}" | tee -a "$LOG_DIR/configure_messaging.log" } check_messaging_service() { log "INFO" "Checking messaging service status..." # Check if messaging service is running if systemctl is-active --quiet aitbc-messaging 2>/dev/null; then log "INFO" "Messaging service is running" return 0 else log "WARN" "Messaging service not running or not installed" return 1 fi } generate_auth_token() { log "INFO" "Generating messaging authentication token..." # Generate random token local token token=$(openssl rand -hex 32) # Store token echo "$token" > "$AUTH_TOKEN_FILE" chmod 600 "$AUTH_TOKEN_FILE" log "SUCCESS" "Authentication token generated and stored" echo "$token" } configure_messaging_auth() { local wallet_name="$1" local password="$2" log "INFO" "Configuring messaging authentication for wallet: $wallet_name" cd "$AITBC_DIR" # Generate auth token local token token=$(generate_auth_token) # Configure wallet for messaging log "INFO" "Registering wallet with messaging service..." ./aitbc-cli agent message --wallet "$wallet_name" --password "$password" --auth-token "$token" || log "WARN" "Messaging registration may have failed" log "SUCCESS" "Messaging authentication configured for $wallet_name" } test_messaging_connectivity() { log "INFO" "Testing messaging connectivity..." cd "$AITBC_DIR" # Send test message local test_result test_result=$(./aitbc-cli agent message --topic "test-topic" --message "test-message" 2>&1 || echo "failed") if [[ "$test_result" == *"failed"* ]] || [[ "$test_result" == *"error"* ]]; then log "WARN" "Messaging connectivity test failed" return 1 else log "SUCCESS" "Messaging connectivity test passed" return 0 fi } setup_messaging_config() { log "INFO" "Setting up messaging configuration..." # Create messaging config directory mkdir -p /var/lib/aitbc/messaging # Create basic config cat > /var/lib/aitbc/messaging/config.json <