robot_face_rec/start.sh

63 lines
1.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# --- 日志相关 ---
LOG_DIR="/home/unitree/robot_face_rec/logs/face_rec"
mkdir -p "$LOG_DIR"
LOG_FILE="$LOG_DIR/face_rec_$(date +%Y%m%d_%H%M%S).log"
{
echo "===== $(date) Starting face_rec script ====="
echo "User: $(whoami)"
echo "PWD before cd: $(pwd)"
echo "Python: $(which python) / Version: $(python --version 2>&1)"
} >> "$LOG_FILE"
# 切换到项目目录
cd /home/unitree/robot_face_rec || {
echo "Failed to cd to project dir" >> "$LOG_FILE"
exit 1
}
{
echo "PWD after cd: $(pwd)"
echo "Env before display detection: DISPLAY=$DISPLAY, XAUTHORITY=$XAUTHORITY"
} >> "$LOG_FILE"
# --- 动态检测 DISPLAY 的逻辑 ---
# 方法:尝试从正在运行的 Xorg / X 进程环境中读取 DISPLAY
display_found=""
for pid in $(pgrep Xorg); do
if [ -r /proc/$pid/environ ]; then
disp=$(tr '\0' '\n' < /proc/$pid/environ | grep '^DISPLAY=' | cut -d'=' -f2-)
if [ -n "$disp" ]; then
# display_found="$disp"
echo "Chosen "
break
fi
fi
done
# 如果还没找到 DISPLAY则尝试 fallback
if [ -z "$display_found" ]; then
# 常见默认::0
display_found=":0"
echo "Chosen default"
fi
export DISPLAY="$display_found"
{
echo "Chosen DISPLAY = $DISPLAY"
} >> "$LOG_FILE"
# XAUTHORITY假设用户的 .Xauthority 存在于 home 目录
export XAUTHORITY="/home/unitree/.Xauthority"
{
echo "Using XAUTHORITY = $XAUTHORITY"
} >> "$LOG_FILE"
# 最终执行 Python 程序(不后台化,用 exec 替换进程)
exec python face_rec.py >> "$LOG_FILE" 2>&1