File size: 1,144 Bytes
89a43e1
 
 
47b92c5
89a43e1
 
 
 
47b92c5
 
 
 
89a43e1
 
 
 
 
 
 
 
47b92c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89a43e1
 
47b92c5
89a43e1
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
set -eu

REPO_API_URL="https://api.github.com/repos/caidaoli/CLIProxyAPI/releases/latest"
EXTRACT_DIR="/tmp/cliproxyapi"

asset_url="$({
  curl -fsSL "$REPO_API_URL" \
    | grep -Eo '"browser_download_url"[[:space:]]*:[[:space:]]*"[^"]*"' \
    | cut -d '"' -f 4 \
    | grep -E '/[^/]*linux[-_]amd64(\.tar\.gz)?$' \
    | head -n 1
} || true)"

if [ -z "${asset_url}" ]; then
  echo "错误: 未找到 linux amd64 发布包 URL" >&2
  exit 1
fi

echo "下载: ${asset_url}"
download_path="/tmp/$(basename "$asset_url")"
echo "保存到: ${download_path}"
curl -fsSL "$asset_url" -o "$download_path"

case "$download_path" in
  *.tar.gz)
    rm -rf "$EXTRACT_DIR"
    mkdir -p "$EXTRACT_DIR"
    tar -xzf "$download_path" -C "$EXTRACT_DIR"
    binary_path="$({
      find "$EXTRACT_DIR" -maxdepth 2 -type f \( -name 'cli-proxy-api' -o -name 'CLIProxyAPI' \) | head -n 1
    } || true)"
    ;;
  *)
    binary_path="$download_path"
    ;;
esac

if [ -z "${binary_path}" ]; then
  echo "错误: 未找到 cli-proxy-api 可执行文件" >&2
  exit 1
fi

chmod +x "$binary_path"
echo "启动: ${binary_path} $*"
exec "$binary_path" "$@"