fix: 修复 manage.sh 脚本软链接创建时的路径问题

- 修复找不到脚本文件 /root/claude-relay-service/app/manage.sh 的错误
- 优先使用项目中的 $APP_DIR/scripts/manage.sh 路径
- 改进 load_config 函数以支持不同的项目目录结构
- 添加 symlink 命令执行前的检查,确保 APP_DIR 已设置
- 增加详细的诊断信息输出,方便调试路径问题

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
shaw
2025-08-03 23:16:31 +08:00
parent 5378cb8910
commit 29b331c7b4

View File

@@ -938,7 +938,14 @@ handle_menu_choice() {
create_symlink() { create_symlink() {
# 获取脚本的绝对路径 # 获取脚本的绝对路径
local script_path="" local script_path=""
if command_exists realpath; then
# 优先使用项目中的 manage.sh在 app/scripts 目录下)
if [ -n "$APP_DIR" ] && [ -f "$APP_DIR/scripts/manage.sh" ]; then
script_path="$APP_DIR/scripts/manage.sh"
elif [ -f "/app/scripts/manage.sh" ] && [ "$(basename "$0")" = "manage.sh" ]; then
# Docker 容器中的路径
script_path="/app/scripts/manage.sh"
elif command_exists realpath; then
script_path="$(realpath "$0")" script_path="$(realpath "$0")"
elif command_exists readlink && readlink -f "$0" >/dev/null 2>&1; then elif command_exists readlink && readlink -f "$0" >/dev/null 2>&1; then
script_path="$(readlink -f "$0")" script_path="$(readlink -f "$0")"
@@ -950,11 +957,22 @@ create_symlink() {
local symlink_path="/usr/bin/crs" local symlink_path="/usr/bin/crs"
print_info "创建命令行快捷方式..." print_info "创建命令行快捷方式..."
print_info "APP_DIR: $APP_DIR"
print_info "脚本路径: $script_path" print_info "脚本路径: $script_path"
# 检查脚本文件是否存在 # 检查脚本文件是否存在
if [ ! -f "$script_path" ]; then if [ ! -f "$script_path" ]; then
print_error "找不到脚本文件: $script_path" print_error "找不到脚本文件: $script_path"
print_info "当前目录: $(pwd)"
print_info "脚本参数 \$0: $0"
if [ -n "$APP_DIR" ]; then
print_info "检查项目目录结构:"
ls -la "$APP_DIR/" 2>/dev/null | head -5
if [ -d "$APP_DIR/scripts" ]; then
print_info "scripts 目录内容:"
ls -la "$APP_DIR/scripts/" 2>/dev/null | grep manage.sh
fi
fi
return 1 return 1
fi fi
@@ -1004,7 +1022,15 @@ load_config() {
fi fi
if [ -n "$INSTALL_DIR" ]; then if [ -n "$INSTALL_DIR" ]; then
APP_DIR="$INSTALL_DIR/app" # 检查是否使用了标准的安装结构(项目在 app 子目录)
if [ -d "$INSTALL_DIR/app" ] && [ -f "$INSTALL_DIR/app/package.json" ]; then
APP_DIR="$INSTALL_DIR/app"
# 检查是否直接克隆了项目(项目在根目录)
elif [ -f "$INSTALL_DIR/package.json" ]; then
APP_DIR="$INSTALL_DIR"
else
APP_DIR="$INSTALL_DIR/app"
fi
# 加载.env配置 # 加载.env配置
if [ -f "$APP_DIR/.env" ]; then if [ -f "$APP_DIR/.env" ]; then
@@ -1077,6 +1103,12 @@ main() {
;; ;;
symlink) symlink)
# 单独创建软链接 # 单独创建软链接
# 确保 APP_DIR 已设置
if [ -z "$APP_DIR" ]; then
print_error "请先安装项目后再创建软链接"
print_info "运行: $0 install"
exit 1
fi
create_symlink create_symlink
;; ;;
help) help)