hequ commited on
Commit
63cbd34
·
verified ·
1 Parent(s): 4f15220

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +33 -21
start.sh CHANGED
@@ -21,12 +21,13 @@ SWITCH_PREVIEW_MODEL="${SWITCH_PREVIEW_MODEL:-true}"
21
  # ===== 目录准备 =====
22
  mkdir -p "$(dirname "$CONFIG_PATH")" "$AUTH_DIR" || true
23
 
24
- # ===== API Keys(逗号或换行)=====
25
  API_KEYS_INPUT="${API_KEYS:-}"
26
  API_KEYS_YAML="[]"
27
  if [ -n "$API_KEYS_INPUT" ]; then
28
  tmp="/tmp/_keys.yaml"
29
  : > "$tmp"
 
30
  echo "$API_KEYS_INPUT" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sed '/^$/d' | \
31
  while IFS= read -r key; do
32
  esc=$(printf '%s' "$key" | sed 's/\\/\\\\/g; s/"/\\"/g')
@@ -61,37 +62,48 @@ EOF
61
  echo "INFO: config.yaml 已生成于 $CONFIG_PATH"
62
  echo "INFO: auth-dir = $AUTH_DIR"
63
 
64
- # ===== 自动探测可执行文件并启动 =====
65
- try_exec() {
66
- if [ -x "$1" ]; then
67
- echo "INFO: 使用可执行文件: $1"
68
- exec "$1" --config "$CONFIG_PATH"
69
- fi
 
 
 
 
70
  }
71
 
72
  # 1) PATH 中尝试(大写/小写名称)
73
  if command -v CLIProxyAPI >/dev/null 2>&1; then
74
- exec CLIProxyAPI --config "$CONFIG_PATH"
75
  fi
76
  if command -v cli-proxy-api >/dev/null 2>&1; then
77
- exec cli-proxy-api --config "$CONFIG_PATH"
78
  fi
79
 
80
- # 2) 常见绝对路径(优先常用的 /CLIProxyAPI/CLIProxyAPI)
81
- try_exec /CLIProxyAPI/CLIProxyAPI
82
- try_exec /CLIProxyAPI/cli-proxy-api
83
- try_exec /usr/local/bin/CLIProxyAPI
84
- try_exec /usr/bin/CLIProxyAPI
85
- try_exec /bin/CLIProxyAPI
86
- try_exec /usr/local/bin/cli-proxy-api
87
- try_exec /usr/bin/cli-proxy-api
88
- try_exec /bin/cli-proxy-api
 
 
 
 
 
 
 
89
 
90
  # 3) 兜底:列目录帮助定位
91
- echo "FATAL: 找不到 CLIProxyAPI 可执行文件。列出常见目录帮助排查:"
92
- echo "------ ls -l /CLIProxyAPI ------"
93
  ls -l /CLIProxyAPI 2>/dev/null || true
94
- echo "------ which -a CLIProxyAPI / cli-proxy-api ------"
95
  which -a CLIProxyAPI 2>/dev/null || true
96
  which -a cli-proxy-api 2>/dev/null || true
97
  exit 127
 
21
  # ===== 目录准备 =====
22
  mkdir -p "$(dirname "$CONFIG_PATH")" "$AUTH_DIR" || true
23
 
24
+ # ===== 注入 API Keys(支持逗号或换行)=====
25
  API_KEYS_INPUT="${API_KEYS:-}"
26
  API_KEYS_YAML="[]"
27
  if [ -n "$API_KEYS_INPUT" ]; then
28
  tmp="/tmp/_keys.yaml"
29
  : > "$tmp"
30
+ # 先按逗号拆,再清理空白/空行
31
  echo "$API_KEYS_INPUT" | tr ',' '\n' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | sed '/^$/d' | \
32
  while IFS= read -r key; do
33
  esc=$(printf '%s' "$key" | sed 's/\\/\\\\/g; s/"/\\"/g')
 
62
  echo "INFO: config.yaml 已生成于 $CONFIG_PATH"
63
  echo "INFO: auth-dir = $AUTH_DIR"
64
 
65
+ # --- Postgres 本地镜像兜底:只用 /tmp ---
66
+ if [ -n "${PGSTORE_DSN:-}" ]; then
67
+ export PGSTORE_LOCAL_PATH="${PGSTORE_LOCAL_PATH:-/tmp}"
68
+ mkdir -p "${PGSTORE_LOCAL_PATH}/pgstore" || true
69
+ fi
70
+
71
+ # ===== 启动:自动探测可执行文件;启动前切到 /tmp(解决管理静态资源缓存告警)=====
72
+ exec_with_cd() {
73
+ cd /tmp || true
74
+ exec "$1" --config "$CONFIG_PATH"
75
  }
76
 
77
  # 1) PATH 中尝试(大写/小写名称)
78
  if command -v CLIProxyAPI >/dev/null 2>&1; then
79
+ exec_with_cd "$(command -v CLIProxyAPI)"
80
  fi
81
  if command -v cli-proxy-api >/dev/null 2>&1; then
82
+ exec_with_cd "$(command -v cli-proxy-api)"
83
  fi
84
 
85
+ # 2) 常见绝对路径(优先你已验证可用的 /CLIProxyAPI/CLIProxyAPI)
86
+ for p in \
87
+ /CLIProxyAPI/CLIProxyAPI \
88
+ /CLIProxyAPI/cli-proxy-api \
89
+ /usr/local/bin/CLIProxyAPI \
90
+ /usr/local/bin/cli-proxy-api \
91
+ /usr/bin/CLIProxyAPI \
92
+ /usr/bin/cli-proxy-api \
93
+ /bin/CLIProxyAPI \
94
+ /bin/cli-proxy-api
95
+ do
96
+ if [ -x "$p" ]; then
97
+ echo "INFO: 使用可执行文件: $p"
98
+ exec_with_cd "$p"
99
+ fi
100
+ done
101
 
102
  # 3) 兜底:列目录帮助定位
103
+ echo "FATAL: 找不到 CLIProxyAPI 可执行文件。列出常见目录帮助排查:" >&2
104
+ echo "------ ls -l /CLIProxyAPI ------" >&2
105
  ls -l /CLIProxyAPI 2>/dev/null || true
106
+ echo "------ which -a CLIProxyAPI / cli-proxy-api ------" >&2
107
  which -a CLIProxyAPI 2>/dev/null || true
108
  which -a cli-proxy-api 2>/dev/null || true
109
  exit 127