#!/bin/sh
# Show relay fingerprint

FINGERPRINT_FILE="${TOR_DATA_DIR:-/var/lib/tor}/fingerprint"

if [ -f "$FINGERPRINT_FILE" ]; then
    echo ""
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo "🔑 Relay Fingerprint"
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo ""

    NICKNAME=$(cat "$FINGERPRINT_FILE" | awk '{print $1}')
    FINGERPRINT=$(cat "$FINGERPRINT_FILE" | awk '{print $2}')

    echo "  🪪 Nickname:    $NICKNAME"
    echo "  🔐 Fingerprint: $FINGERPRINT"
    echo ""

    echo "  📋 Copy/paste:  $NICKNAME $FINGERPRINT"
    echo ""

    echo "  🔍 Find on Tor Metrics:"
    echo "     https://metrics.torproject.org/rs.html#search/$FINGERPRINT"
    echo ""
    echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
    echo ""
else
    echo ""
    echo "⏳ Fingerprint not yet generated"
    echo ""
    echo "The fingerprint is created after Tor starts. Please wait a moment"
    echo "and try again. Check status with: docker exec <container> status"
    echo ""
    exit 1
fi