-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_webhook.sh
More file actions
executable file
·46 lines (35 loc) · 1.35 KB
/
Copy pathget_webhook.sh
File metadata and controls
executable file
·46 lines (35 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
set -e
# get_webhook.sh: Start Flask server, establish localhost.run tunnel, and output webhook URL.
# Assumes user has SSH key at ~/.ssh/id_rsa (protected by ssh-agent or passphrase prompt).
# 1. Start Flask server in the background
echo "🚀 啟動 Flask server..."
# Use python3 explicitly
env python3 app.py > flask.log 2>&1 &
FLASK_PID=$!
# Give Flask time to start
sleep 2
# 2. Start SSH tunnel using openssh from nix-shell
echo "🌐 建立 localhost.run 隧道..."
nix-shell -p openssh --run \
"ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
-R 80:localhost:5000 ssh.localhost.run 2>&1 | tee tunnel.log" &
TUNNEL_PID=$!
# Wait briefly for tunnel setup
sleep 3
# 3. Extract public URL from tunnel log
WEBHOOK_URL=$(grep -Eo "https?://[a-zA-Z0-9.-]+\\.lhr\\.life" tunnel.log | head -n1)
if [[ -z "$WEBHOOK_URL" ]]; then
echo "❌ 無法取得 webhook URL,請確認隧道與 SSH 金鑰設定是否正確。"
kill $TUNNEL_PID $FLASK_PID 2>/dev/null || true
exit 1
fi
# 4. Output the webhook URL
echo "✅ 你的公開 Webhook URL:"
echo "$WEBHOOK_URL/webhook"
# 5. Clean up on exit
trap "echo 'Stopping...'; kill $TUNNEL_PID $FLASK_PID; exit" SIGINT SIGTERM
# 6. Keep script alive to maintain processes
echo "📡 正在接收 webhook...(按 Ctrl+C 可停止)"
wait $TUNNEL_PID