ccx / entrypoint.sh
ahutchen's picture
Upload 2 files
47b92c5 verified
#!/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" "$@"