Files
mediaplayer/start_linux.sh
2026-08-11 14:14:56 +08:00

44 lines
1.4 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.
#!/usr/bin/env bash
# 媒体播放器启动脚本Linux
# 自动激活名为 mediaplayer 的 conda 环境并启动播放器
cd "$(dirname "$0")"
# 1. 如果 conda 已在 PATH 中,直接使用它的基础目录
if command -v conda >/dev/null 2>&1; then
CONDA_BASE="$(conda info --base 2>/dev/null)"
fi
# 2. 否则在常见安装位置查找
if [ -z "${CONDA_BASE:-}" ]; then
for base in "$HOME/anaconda3" "$HOME/miniconda3" /opt/anaconda3 /opt/miniconda3; do
if [ -f "$base/etc/profile.d/conda.sh" ]; then
CONDA_BASE="$base"
break
fi
done
fi
if [ -z "${CONDA_BASE:-}" ] || [ ! -f "$CONDA_BASE/etc/profile.d/conda.sh" ]; then
echo "[错误] 未找到 conda请先安装 Anaconda 或 Miniconda。"
read -r -p "按回车键退出..." _
exit 1
fi
# 3. 加载 conda 的 shell 函数并激活环境
source "$CONDA_BASE/etc/profile.d/conda.sh"
if ! conda activate mediaplayer; then
echo "[错误] 激活 mediaplayer 环境失败,请确认已创建该环境。"
read -r -p "按回车键退出..." _
exit 1
fi
# 4. 确认环境已激活(防止意外使用系统 Python
if ! python -c "import sys; sys.exit(0 if 'mediaplayer' in sys.prefix else 1)"; then
echo "[错误] mediaplayer 环境未正确激活。"
read -r -p "按回车键退出..." _
exit 1
fi
exec python media_player.py "$@"