24 lines
1.2 KiB
Bash
Executable File
Raw Permalink 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
# 修 .env.oe-package 里的死路径:PYTHON_BIN 指向 <项目根>/oellm2/venv/bin/python,实际 QAT venv 在 ~/toolchains/oellm2/venv。
# agent 按规则会读这个文件,所以 P1 第一件事。备份为 .env.oe-package.bak-<日期>。
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
F="$ROOT/.horizon/.env.oe-package"; [ -f "$F" ] || F="$ROOT/.env.oe-package"
[ -f "$F" ] || { echo "没有 .env.oe-package(找了 .horizon/ 与项目根)"; exit 1; }
NEW="${1:-$HOME/toolchains/oellm2/venv/bin/python}"
[ -x "$NEW" ] || { echo "目标解释器不存在: $NEW"; exit 2; }
cp -n "$F" "$F.bak-$(date +%Y%m%d)" || true
echo "before:"; grep -n '^PYTHON_BIN=' "$F" || echo " (no PYTHON_BIN line)"
if grep -q '^PYTHON_BIN=' "$F"; then
sed -i.tmp "s|^PYTHON_BIN=.*|PYTHON_BIN=$NEW|" "$F" && rm -f "$F.tmp"
else
echo "PYTHON_BIN=$NEW" >> "$F"
fi
echo "after:"; grep -n '^PYTHON_BIN=' "$F"
# 顺手核对所有以 / 或 ~ 开头的路径值
echo "--- 其他路径值核对 ---"
grep -E '^[A-Z_]+=(/|~|\$HOME)' "$F" | while IFS='=' read -r k v; do
p="${v/#\~/$HOME}"; p="${p/#\$HOME/$HOME}"
[ -e "$p" ] && echo "ok $k=$v" || echo "MISS $k=$v"
done