-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_corecast_host.sh
More file actions
executable file
·87 lines (74 loc) · 2.6 KB
/
start_corecast_host.sh
File metadata and controls
executable file
·87 lines (74 loc) · 2.6 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# Core Cast Host - Secure SOCKS Proxy (Dynamic REVERSE Tunnel)
#
# This version creates a SOCKS proxy on the server (port 8080)
# which can dynamically handle any port the SDR needs.
# --- Function to Check Soapy Server Status ---
check_soapy_server() {
local port="$1"
local max_attempts=10
local attempt=0
echo "Checking for local soapy_server on port $port..."
while [ $attempt -lt $max_attempts ]; do
if ss -tuln | grep -q ":$port\>"; then
echo "✅ soapy_server detected and listening on port $port."
return 0
fi
attempt=$((attempt + 1))
echo " Attempt $attempt/$max_attempts: soapy_server not ready. Waiting 5 seconds..."
sleep 5
done
echo "❌ ERROR: soapy_server failed to start or listen on port $port after $max_attempts attempts."
echo " Please check the status of the soapyremote-server service."
return 1
}
# --- Auto-load .env if running manually ---
if [ -z "$CORECAST_SERVER_IP" ]; then
echo "Variables not set. Attempting to load from .env file..."
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
ENV_FILE="$SCRIPT_DIR/.env"
if [ -f "$ENV_FILE" ]; then
echo "Found .env, loading and exporting variables..."
set -a
source "$ENV_FILE"
set +a
else
echo "Warning: .env file not found at $ENV_FILE"
fi
fi
# --- Parameter Validation ---
if [ -z "$CORECAST_SERVER_IP" ] || \
[ -z "$CORECAST_SERVER_PORT" ] || \
[ -z "$CORECAST_SSH_USER" ] || \
[ -z "$SOAPY_SERVER_PORT" ] || \
[ -z "$CORECAST_SERVER_PASS" ]; then
echo "Error: Critical configuration environment variables are missing."
exit 1
fi
# --- Pre-Flight Check ---
# Check if soapy_server is running on its *main* port (e.g., 55132)
if ! check_soapy_server "$SOAPY_SERVER_PORT"; then
exit 1
fi
echo "Attempting to establish Core Cast SOCKS proxy tunnel to $CORECAST_SSH_USER@$CORECAST_SERVER_IP:$CORECAST_SERVER_PORT..."
# --- Secure SSH Command Execution ---
export SSHPASS="$CORECAST_SERVER_PASS"
#
# ▼▼▼ THE FIX (Back to SOCKS) ▼▼▼
#
# -N: Do not execute a remote command.
# -T: Disable pseudo-terminal allocation.
# -R 8080: Create a REVERSE dynamic SOCKS proxy on the
# *remote server's* 127.0.0.1:8080.
#
exec /usr/bin/sshpass -e /usr/bin/ssh \
-N \
-T \
-R 8080 \
-p "$CORECAST_SERVER_PORT" \
-o "StrictHostKeyChecking=no" \
-o "UserKnownHostsFile=/dev/null" \
-o "ServerAliveInterval=60" \
-o "ExitOnForwardFailure=yes" \
"$CORECAST_SSH_USER@$CORECAST_SERVER_IP"
echo "SSH command exited."