#!/bin/bash # 创建日志目录 LOG_DIR="/home/unitree/robot_face_rec/logs" mkdir -p "$LOG_DIR" # 切换到项目目录 cd /home/unitree/robot_face_rec || { echo "Failed to cd to project dir" exit 1 } # 设置DISPLAY环境变量 # 使用Linux系统最常见的默认值:0 export DISPLAY=":0" echo "Using DISPLAY: $DISPLAY" # 设置XAUTHORITY环境变量 # 先尝试从Xorg进程命令行获取 xauth_path="" for pid in $(pgrep Xorg); do if [ -r /proc/$pid/cmdline ]; then cmdline=$(tr '\0' ' ' < /proc/$pid/cmdline) # 使用更兼容的方式提取auth参数 xauth_path=$(echo "$cmdline" | awk '/-auth/{print $2}' | head -1) if [ -n "$xauth_path" ]; then break fi fi done # 如果没有找到,检查常见的XAUTHORITY路径 if [ -z "$xauth_path" ]; then # 检查gdm路径 if [ -f "/run/user/1000/gdm/Xauthority" ]; then xauth_path="/run/user/1000/gdm/Xauthority" # 检查lightdm路径 elif [ -f "/var/run/lightdm/root/:0" ]; then xauth_path="/var/run/lightdm/root/:0" # 默认路径 else xauth_path="/home/unitree/.Xauthority" fi fi export XAUTHORITY="$xauth_path" echo "Using XAUTHORITY: $XAUTHORITY" # 执行 Python 程序(Python 代码自己管理日志) exec python face_rec.py