-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-source-linux.sh
More file actions
executable file
·182 lines (158 loc) · 5.52 KB
/
run-source-linux.sh
File metadata and controls
executable file
·182 lines (158 loc) · 5.52 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
#
# StreamGRID - Linux Source Runner
# Clean start script with port management
#
set -e
# ============================================
# PORT CONFIGURATION (Random High Ports)
# ============================================
DEV_SERVER_PORT=52774
ELECTRON_DEBUG_PORT=60000
ELECTRON_INSPECT_PORT=63689
# ============================================
# COLORS
# ============================================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
NC='\033[0m'
# ============================================
# FUNCTIONS
# ============================================
print_header() {
echo -e "${CYAN}"
echo "================================================================"
echo " StreamGRID - Linux Source Runner"
echo "================================================================"
echo -e "${NC}"
}
check_and_kill_port() {
local port=$1
local name=$2
local pid=$(lsof -ti :$port 2>/dev/null || true)
if [ -n "$pid" ]; then
echo -e "${YELLOW}[CLEANUP]${NC} Killing process on port $port ($name) - PID: $pid"
kill -9 $pid 2>/dev/null || true
sleep 0.5
fi
}
kill_zombie_electrons() {
echo -e "${BLUE}[CLEANUP]${NC} Checking for orphaned Electron processes..."
local pids=$(pgrep -f "electron.*$(basename $(pwd))" 2>/dev/null || true)
if [ -n "$pids" ]; then
echo -e "${YELLOW}[CLEANUP]${NC} Killing orphaned Electron processes: $pids"
echo "$pids" | xargs -r kill -9 2>/dev/null || true
sleep 1
fi
local dir_pids=$(pgrep -f "electron $(pwd)" 2>/dev/null || true)
if [ -n "$dir_pids" ]; then
echo -e "${YELLOW}[CLEANUP]${NC} Killing Electron processes in project dir: $dir_pids"
echo "$dir_pids" | xargs -r kill -9 2>/dev/null || true
sleep 1
fi
local vite_pids=$(pgrep -f "vite.*$DEV_SERVER_PORT" 2>/dev/null || true)
if [ -n "$vite_pids" ]; then
echo -e "${YELLOW}[CLEANUP]${NC} Killing Vite processes: $vite_pids"
echo "$vite_pids" | xargs -r kill -9 2>/dev/null || true
sleep 1
fi
}
check_dependencies() {
echo -e "${BLUE}[CHECK]${NC} Verifying dependencies..."
if ! command -v node &> /dev/null; then
echo -e "${RED}[ERROR]${NC} Node.js is not installed!"
exit 1
fi
echo -e "${GREEN}[OK]${NC} Node.js $(node --version)"
if ! command -v npm &> /dev/null; then
echo -e "${RED}[ERROR]${NC} npm is not installed!"
exit 1
fi
echo -e "${GREEN}[OK]${NC} npm $(npm --version)"
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}[SETUP]${NC} Installing dependencies..."
npm install
fi
}
fix_linux_sandbox() {
echo -e "${BLUE}[FIX]${NC} Checking Linux sandbox configuration..."
local current=$(cat /proc/sys/kernel/unprivileged_userns_clone 2>/dev/null || echo "1")
if [ "$current" = "0" ]; then
echo -e "${YELLOW}[FIX]${NC} Enabling unprivileged user namespaces for Electron..."
echo "1234" | sudo -S sysctl -w kernel.unprivileged_userns_clone=1 2>/dev/null || true
fi
echo -e "${GREEN}[OK]${NC} Sandbox configuration ready"
}
# ============================================
# MAIN EXECUTION
# ============================================
cd "$(dirname "$0")"
print_header
echo -e "${BLUE}[INFO]${NC} Working directory: $(pwd)"
echo -e "${BLUE}[INFO]${NC} Configured ports:"
echo " - Dev Server: $DEV_SERVER_PORT"
echo " - Electron Debug: $ELECTRON_DEBUG_PORT"
echo " - Electron Inspect: $ELECTRON_INSPECT_PORT"
echo ""
# Cleanup phase
echo -e "${CYAN}--- CLEANUP PHASE ---${NC}"
kill_zombie_electrons
check_and_kill_port $DEV_SERVER_PORT "Dev Server"
check_and_kill_port $ELECTRON_DEBUG_PORT "Electron Debug"
check_and_kill_port $ELECTRON_INSPECT_PORT "Electron Inspect"
echo ""
# Verification phase
echo -e "${CYAN}--- VERIFICATION PHASE ---${NC}"
check_dependencies
fix_linux_sandbox
echo ""
# Build phase
echo -e "${CYAN}--- BUILD PHASE ---${NC}"
echo -e "${BLUE}[BUILD]${NC} Compiling main process TypeScript..."
npm run build:main
echo -e "${GREEN}[OK]${NC} Main process compiled"
echo ""
# Launch phase
echo -e "${CYAN}--- LAUNCH PHASE ---${NC}"
export NODE_ENV=development
export ELECTRON_FORCE_WINDOW_MENU_BAR=1
export ELECTRON_TRASH=gio
# Start Vite dev server in the background
echo -e "${BLUE}[VITE]${NC} Starting renderer dev server on port $DEV_SERVER_PORT..."
npx vite --port $DEV_SERVER_PORT &
VITE_PID=$!
# Cleanup handler — kill Vite when script exits
cleanup() {
echo ""
echo -e "${YELLOW}[SHUTDOWN]${NC} Stopping Vite dev server (PID: $VITE_PID)..."
kill $VITE_PID 2>/dev/null || true
wait $VITE_PID 2>/dev/null || true
echo -e "${GREEN}[OK]${NC} All processes stopped."
}
trap cleanup EXIT INT TERM
# Wait for Vite to be ready
echo -e "${BLUE}[WAIT]${NC} Waiting for Vite dev server..."
for i in $(seq 1 30); do
if curl -s -o /dev/null http://localhost:$DEV_SERVER_PORT 2>/dev/null; then
echo -e "${GREEN}[OK]${NC} Vite dev server ready"
break
fi
if [ $i -eq 30 ]; then
echo -e "${RED}[ERROR]${NC} Vite dev server failed to start within 30s"
exit 1
fi
sleep 1
done
echo -e "${GREEN}[START]${NC} Launching StreamGRID..."
echo ""
if [ "$1" = "--dev" ] || [ "$1" = "-d" ]; then
echo -e "${MAGENTA}[MODE]${NC} Development mode with DevTools"
npx electron . --no-sandbox --dev --remote-debugging-port=$ELECTRON_DEBUG_PORT --inspect=$ELECTRON_INSPECT_PORT
else
echo -e "${GREEN}[MODE]${NC} Standard mode"
npx electron . --no-sandbox
fi