#!/bin/bash # example-usage.sh — Example showing how to use the tailscale-gitea module # Issue: timmy-home#385 — Standardized Tailscale IP detection module set -euo pipefail # --- Basic Usage --- # Source the module to automatically set GITEA_BASE_URL SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${SCRIPT_DIR}/tailscale-gitea.sh" # Now use GITEA_BASE_URL in your API calls echo "Using Gitea at: $GITEA_BASE_URL" echo "Tailscale active: $GITEA_USING_TAILSCALE" # --- Example API Call --- # curl -sf -H "Authorization: token $TOKEN" \ # "$GITEA_BASE_URL/repos/myuser/myrepo/issues" # --- Custom Configuration (Optional) --- # You can customize behavior by setting variables BEFORE sourcing: # # TAILSCALE_TIMEOUT=5 # Wait 5 seconds instead of 2 # TAILSCALE_DEBUG=1 # Print which endpoint was selected # source "${SCRIPT_DIR}/tailscale-gitea.sh" # --- Advanced: Checking Network Mode --- if [[ "$GITEA_USING_TAILSCALE" == "true" ]]; then echo "✓ Connected via private Tailscale network" else echo "⚠ Using public internet fallback (Tailscale unavailable)" fi # --- Example: Polling with Retry Logic --- poll_gitea() { local endpoint="${1:-$GITEA_BASE_URL}" local max_retries="${2:-3}" local retry=0 while [[ $retry -lt $max_retries ]]; do if curl -sf --connect-timeout 2 "${endpoint}/version" > /dev/null 2>&1; then echo "Gitea is reachable" return 0 fi retry=$((retry + 1)) echo "Retry $retry/$max_retries..." sleep 1 done echo "Gitea unreachable after $max_retries attempts" return 1 } # Uncomment to test connectivity: # poll_gitea "$GITEA_BASE_URL"