Skip to content

Commit 11452a4

Browse files
committed
fix(scripts): add FFmpeg detection and dynamic port allocation for Linux startup
1 parent ac70166 commit 11452a4

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

script/start-linux.sh

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,38 @@ fi
8181
chmod +x $SCRIPT_DIR/llbot/node
8282
chmod +x $SCRIPT_DIR/llbot/pmhq
8383

84+
# 检测 FFmpeg 是否已安装
85+
if ! command -v ffmpeg &> /dev/null; then
86+
echo "未检测到 FFmpeg,正在安装..."
87+
sudo apt-get install -y ffmpeg
88+
if [ $? -ne 0 ]; then
89+
echo "警告:FFmpeg 安装失败,音视频处理功能可能受限"
90+
else
91+
echo "FFmpeg 安装完成"
92+
fi
93+
fi
94+
95+
# 寻找可用端口(从 13000 开始)
96+
find_available_port() {
97+
local port=$1
98+
while [ $port -lt 65535 ]; do
99+
if ! ss -tuln | grep -q ":$port "; then
100+
echo $port
101+
return 0
102+
fi
103+
port=$((port + 1))
104+
done
105+
echo ""
106+
return 1
107+
}
108+
109+
AVAILABLE_PORT=$(find_available_port 13000)
110+
if [ -z "$AVAILABLE_PORT" ]; then
111+
echo "错误:无法找到可用端口"
112+
exit 1
113+
fi
114+
115+
84116
# 检测 xvfb-run 命令是否存在
85117
USE_XVFB=1
86118
if ! command -v xvfb-run &> /dev/null; then
@@ -96,10 +128,12 @@ if ! command -v xvfb-run &> /dev/null; then
96128
fi
97129
fi
98130

99-
$SCRIPT_DIR/llbot/node $SCRIPT_DIR/llbot/llonebot.js &
100131

101132
if [ $USE_XVFB -eq 1 ]; then
102-
sudo xvfb-run $SCRIPT_DIR/llbot/pmhq
133+
sudo xvfb-run $SCRIPT_DIR/llbot/pmhq --port=$AVAILABLE_PORT &
103134
else
104-
sudo $SCRIPT_DIR/llbot/pmhq
135+
sudo $SCRIPT_DIR/llbot/pmhq --port=$AVAILABLE_PORT &
105136
fi
137+
sleep 5
138+
139+
$SCRIPT_DIR/llbot/node $SCRIPT_DIR/llbot/llonebot.js -- --pmhq-port=$AVAILABLE_PORT &

0 commit comments

Comments
 (0)