#!/bin/bash

# 1. 清理锁文件
rm -f /tmp/.X99-lock
# 清理 DBus 锁文件 (防止重启报错)
rm -f /var/run/dbus/pid

# 2. [新增] 启动 DBus 服务
mkdir -p /var/run/dbus
dbus-daemon --system --fork

# 3. 启动 Xvfb
Xvfb :99 -ac -screen 0 1920x1080x24 -nolisten tcp &

# 等待服务就绪
echo "Waiting for Xvfb and DBus..."
sleep 3

# 5. 执行外部传进来的命令 (如 python3 main_sentinel.py)
if [ $# -eq 0 ]; then
    echo "No command provided, starting bash..."
    exec bash
else
    echo "Executing command: $@"
    exec "$@"
fi