File size: 1,813 Bytes
7a4c980
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
#!/usr/bin/env bash
set -ex

echo "[ENTRYPOINT] Starting WireGuard HTTP Proxy"

# Check if WireGuard config should be generated
if [[ -z "${WIREGUARD_INTERFACE_PRIVATE_KEY}" ]]; then
    echo "[ENTRYPOINT] Generating Cloudflare Warp configuration..."
    
    # Run warp binary to generate config
    WARP_OUTPUT=$(warp)
    
    # Parse the warp output to extract config values
    export WIREGUARD_INTERFACE_PRIVATE_KEY=$(echo "$WARP_OUTPUT" | grep "PrivateKey" | awk '{print $3}')
    export WIREGUARD_INTERFACE_ADDRESS=$(echo "$WARP_OUTPUT" | grep "Address" | awk '{print $3}')
    export WIREGUARD_PEER_PUBLIC_KEY=$(echo "$WARP_OUTPUT" | grep "PublicKey" | awk '{print $3}')
    export WIREGUARD_PEER_ENDPOINT=$(echo "$WARP_OUTPUT" | grep "Endpoint" | awk '{print $3}')
    export WIREGUARD_INTERFACE_DNS="${WIREGUARD_INTERFACE_DNS:-1.1.1.1}"
    
    echo "[ENTRYPOINT] Warp config generated successfully"
else
    echo "[ENTRYPOINT] Using provided WireGuard configuration"
fi

# Start the proxy server in the background
echo "[ENTRYPOINT] Starting HTTP proxy server (internal)..."
server &
SERVER_PID=$!

# Wait for proxy to start
echo "[ENTRYPOINT] Waiting for proxy to be ready on port 8080..."
while ! curl -v http://127.0.0.1:8080/ 2>&1 | grep "Proxy Running"; do
    if ! kill -0 $SERVER_PID 2>/dev/null; then
        echo "[FATAL] Server process exited unexpectedly!"
        wait $SERVER_PID
        exit 1
    fi
    echo "[ENTRYPOINT] Proxy not ready yet... retrying in 1s"
    sleep 1
done
echo "[ENTRYPOINT] Proxy is ready!"

# Start Proxy Check
echo "[ENTRYPOINT] Checking proxy connection..."
curl -s -x http://127.0.0.1:8080 https://cloudflare.com/cdn-cgi/trace
echo ""
echo "[ENTRYPOINT] Proxy check complete."

# Start Streamion
echo "[ENTRYPOINT] Starting Streamion..."
exec deno task dev