Create reusable tailscale-gitea.sh module for all auxiliary scripts: - Automatically detects Tailscale (100.126.61.75) vs public IP (143.198.27.163) - Sets GITEA_BASE_URL and GITEA_USING_TAILSCALE for sourcing scripts - Configurable timeout, debug mode, and endpoint settings - Maintains sovereignty: prefers private Tailscale network Updated scripts: - kimi-heartbeat.sh: now sources the module - kimi-mention-watcher.sh: added fallback support via module Files added: - uniwizard/lib/tailscale-gitea.sh (reusable module) - uniwizard/lib/example-usage.sh (usage documentation) Acceptance criteria: ✓ Reusable module created and sourceable ✓ kimi-heartbeat.sh updated ✓ kimi-mention-watcher.sh updated (added fallback support) ✓ Example usage script provided
56 lines
1.6 KiB
Bash
56 lines
1.6 KiB
Bash
#!/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"
|