-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathchat
More file actions
executable file
·94 lines (76 loc) · 2.2 KB
/
Copy pathchat
File metadata and controls
executable file
·94 lines (76 loc) · 2.2 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
#!/usr/bin/env bash
set -euo pipefail
CHAT_DIR="$HOME/github/remote-streamerbot-chat"
CHAT_FILE="$CHAT_DIR/chat.html"
SERVER_FILE="$CHAT_DIR/chat-server.py"
PROFILE_DIR="$HOME/.config/streamerbot-chat-profile"
SERVER_HOST="127.0.0.1"
SERVER_PORT="${STREAMERBOT_CHAT_PORT:-8765}"
BROWSER_CMD="${STREAMERBOT_CHAT_BROWSER:-brave-origin-nightly}"
RUNTIME_DIR="$HOME/.cache/streamerbot-chat"
SERVER_PID_FILE="$RUNTIME_DIR/server.pid"
ensure_server_running() {
mkdir -p "$RUNTIME_DIR"
if [[ -f "$SERVER_PID_FILE" ]]; then
local existing_pid
existing_pid="$(cat "$SERVER_PID_FILE" 2>/dev/null || true)"
if [[ -n "$existing_pid" ]] && kill -0 "$existing_pid" 2>/dev/null; then
return
fi
rm -f "$SERVER_PID_FILE"
fi
python3 "$SERVER_FILE" \
--host "$SERVER_HOST" \
--port "$SERVER_PORT" \
--directory "$CHAT_DIR" \
>/dev/null 2>&1 &
local new_pid=$!
echo "$new_pid" > "$SERVER_PID_FILE"
if ! kill -0 "$new_pid" 2>/dev/null; then
echo "Error: failed to start local server on ${SERVER_HOST}:${SERVER_PORT}."
exit 1
fi
}
# Ensure file exists
if [[ ! -f "$CHAT_FILE" ]]; then
echo "Error: $CHAT_FILE not found."
exit 1
fi
if [[ ! -f "$SERVER_FILE" ]]; then
echo "Error: $SERVER_FILE not found."
exit 1
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "Error: python3 is required to serve chat.html over localhost."
exit 1
fi
if ! command -v "$BROWSER_CMD" >/dev/null 2>&1; then
echo "Error: browser command '$BROWSER_CMD' was not found."
exit 1
fi
# Remove only the SingletonLock so Chromium doesn't hand off to a dead session
rm -f "$PROFILE_DIR/SingletonLock" "$PROFILE_DIR/SingletonCookie" "$PROFILE_DIR/SingletonSocket"
ensure_server_running
python3 - <<PY
import socket
import sys
import time
host = ${SERVER_HOST@Q}
port = int(${SERVER_PORT@Q})
for _ in range(50):
try:
with socket.create_connection((host, port), timeout=0.2):
sys.exit(0)
except OSError:
time.sleep(0.1)
sys.exit(1)
PY
"$BROWSER_CMD" \
--user-data-dir="$PROFILE_DIR" \
--disable-gpu \
--ozone-platform=x11 \
--no-first-run \
--no-default-browser-check \
--disable-extensions \
--class="StreamerBotChat" \
"http://${SERVER_HOST}:${SERVER_PORT}/chat.html"