A community based topic aggregation platform built on atproto
1#!/bin/bash
2# Automated ngrok tunnel starter for mobile testing
3# Starts 3 ngrok tunnels and captures their HTTPS URLs
4
5set -e
6
7# Colors
8GREEN='\033[0;32m'
9CYAN='\033[0;36m'
10YELLOW='\033[1;33m'
11NC='\033[0m' # No Color
12
13echo -e "${CYAN}🚀 Starting ngrok tunnels for Coves mobile testing...${NC}"
14echo ""
15
16# Kill any existing ngrok processes
17pkill -f "ngrok http" || true
18sleep 2
19
20# Start ngrok tunnels using separate processes (simpler, works with any config version)
21echo -e "${YELLOW}Starting PDS tunnel (port 3001)...${NC}"
22ngrok http 3001 --log=stdout > /tmp/ngrok-pds.log 2>&1 &
23sleep 1
24
25echo -e "${YELLOW}Starting PLC tunnel (port 3002)...${NC}"
26ngrok http 3002 --log=stdout > /tmp/ngrok-plc.log 2>&1 &
27sleep 1
28
29echo -e "${YELLOW}Starting AppView tunnel (port 8081)...${NC}"
30ngrok http 8081 --log=stdout > /tmp/ngrok-appview.log 2>&1 &
31
32# Get all PIDs
33PIDS=$(pgrep -f "ngrok http")
34NGROK_PID=$PIDS
35
36# Save PID for cleanup
37echo "$NGROK_PID" > /tmp/ngrok-pids.txt
38
39# Wait for ngrok to initialize
40echo ""
41echo -e "${YELLOW}Waiting for tunnels to initialize...${NC}"
42sleep 7
43
44# Fetch URLs from ngrok API (single API at port 4040)
45echo ""
46echo -e "${GREEN}✅ Tunnels started successfully!${NC}"
47echo ""
48echo -e "${CYAN}═══════════════════════════════════════════════════════════${NC}"
49echo -e "${CYAN} NGROK TUNNEL URLS ${NC}"
50echo -e "${CYAN}═══════════════════════════════════════════════════════════${NC}"
51echo ""
52
53# Get all tunnel info
54TUNNELS=$(curl -s http://localhost:4040/api/tunnels 2>/dev/null || echo "")
55
56# Extract URLs by matching port in config.addr
57PDS_URL=$(echo "$TUNNELS" | jq -r '.tunnels[] | select(.config.addr | contains("3001")) | select(.proto=="https") | .public_url' 2>/dev/null | head -1)
58PLC_URL=$(echo "$TUNNELS" | jq -r '.tunnels[] | select(.config.addr | contains("3002")) | select(.proto=="https") | .public_url' 2>/dev/null | head -1)
59APPVIEW_URL=$(echo "$TUNNELS" | jq -r '.tunnels[] | select(.config.addr | contains("8081")) | select(.proto=="https") | .public_url' 2>/dev/null | head -1)
60
61# Fallback if jq filtering fails - just get first 3 HTTPS URLs
62if [ -z "$PDS_URL" ] || [ -z "$PLC_URL" ] || [ -z "$APPVIEW_URL" ]; then
63 echo -e "${YELLOW}⚠️ Port-based matching failed, using fallback...${NC}"
64 URLS=($(echo "$TUNNELS" | jq -r '.tunnels[] | select(.proto=="https") | .public_url' 2>/dev/null))
65 PDS_URL=${URLS[0]:-ERROR}
66 PLC_URL=${URLS[1]:-ERROR}
67 APPVIEW_URL=${URLS[2]:-ERROR}
68fi
69
70echo -e "${GREEN}PDS (3001):${NC} $PDS_URL"
71echo -e "${GREEN}PLC (3002):${NC} $PLC_URL"
72echo -e "${GREEN}AppView (8081):${NC} $APPVIEW_URL"
73
74echo ""
75echo -e "${CYAN}═══════════════════════════════════════════════════════════${NC}"
76echo ""
77
78# Check if any URLs failed
79if [[ "$PDS_URL" == "ERROR" ]] || [[ "$PLC_URL" == "ERROR" ]] || [[ "$APPVIEW_URL" == "ERROR" ]]; then
80 echo -e "${YELLOW}⚠️ Some tunnels failed to start. Check logs:${NC}"
81 echo " tail -f /tmp/ngrok-pds.log"
82 echo " tail -f /tmp/ngrok-plc.log"
83 echo " tail -f /tmp/ngrok-appview.log"
84 exit 1
85fi
86
87# Extract clean URLs (remove https://)
88PDS_CLEAN=$(echo $PDS_URL | sed 's|https://||')
89PLC_CLEAN=$(echo $PLC_URL | sed 's|https://||')
90APPVIEW_CLEAN=$(echo $APPVIEW_URL | sed 's|https://||')
91
92echo -e "${CYAN}📱 Next Steps:${NC}"
93echo ""
94echo -e "1. Update ${YELLOW}coves-mobile/lib/config/environment_config.dart${NC}:"
95echo ""
96echo -e "${GREEN}static const local = EnvironmentConfig(${NC}"
97echo -e "${GREEN} environment: Environment.local,${NC}"
98echo -e "${GREEN} apiUrl: '$APPVIEW_URL',${NC}"
99echo -e "${GREEN} handleResolverUrl: '$PDS_URL/xrpc/com.atproto.identity.resolveHandle',${NC}"
100echo -e "${GREEN} plcDirectoryUrl: '$PLC_URL',${NC}"
101echo -e "${GREEN});${NC}"
102echo ""
103echo -e "2. Run mobile app:"
104echo -e " ${YELLOW}cd /home/bretton/Code/coves-mobile${NC}"
105echo -e " ${YELLOW}flutter run --dart-define=ENVIRONMENT=local${NC}"
106echo ""
107echo -e "3. Login with:"
108echo -e " Handle: ${CYAN}bob.local.coves.dev${NC}"
109echo -e " Password: ${CYAN}bobpass123${NC}"
110echo ""
111echo -e "${YELLOW}💡 Tip: Leave this terminal open. Press Ctrl+C to stop tunnels.${NC}"
112echo -e "${YELLOW} Or run: make ngrok-down${NC}"
113echo ""
114
115# Keep script running (can be killed with Ctrl+C or make ngrok-down)
116wait