|
|
@@ -6,43 +6,61 @@ MIXAPI_BIN="/app/mixapi"
|
|
|
MIXAPI_NEW="/app/mixapi.new"
|
|
|
UPDATE_SCRIPT="/app/check_update.sh"
|
|
|
CRON_FILE="/var/spool/cron/crontabs/root"
|
|
|
-DEFAULT_VERSION="v1.2"
|
|
|
+DEFAULT_VERSION="v2.5.1cl"
|
|
|
|
|
|
-# 国内使用 GitHub 代理加速
|
|
|
-# 支持通过环境变量 GITHUB_PROXY 覆盖默认代理
|
|
|
-# 备用代理列表(按优先级排序)
|
|
|
-GITHUB_PROXY_LIST="${GITHUB_PROXY:-https://ghfast.top https://gh.ddlc.top https://mirror.ghproxy.com https://github.moeyy.xyz}"
|
|
|
+# GitHub 代理列表(按优先级排序,支持通过环境变量 GITHUB_PROXY 覆盖)
|
|
|
+# 格式说明:
|
|
|
+# - 以 / 结尾的代理:直接拼接 GitHub URL(如 https://proxy.com/ + github.com/...)
|
|
|
+# - 不以 / 结尾的代理:需要加 / 再拼接(如 https://proxy.com + / + https://github.com/...)
|
|
|
+# - direct:直接访问 GitHub(不使用代理)
|
|
|
+# 已测试可用的代理:gh.llkk.cc (2024-12)
|
|
|
+GITHUB_PROXY_LIST="${GITHUB_PROXY:-https://gh.llkk.cc https://ghproxy.cn https://ghproxy.net direct}"
|
|
|
|
|
|
-# 测试代理是否可用(快速检测)
|
|
|
-test_proxy() {
|
|
|
+# GitHub API 和下载基础 URL
|
|
|
+GITHUB_API_URL="https://api.github.com/repos/aiprodcoder/MIXAPI/releases/latest"
|
|
|
+GITHUB_DOWNLOAD_BASE="https://github.com/aiprodcoder/MIXAPI/releases/download"
|
|
|
+
|
|
|
+# 构建代理 URL
|
|
|
+# 参数: $1=代理, $2=目标URL
|
|
|
+build_proxy_url() {
|
|
|
local proxy=$1
|
|
|
- local test_url="${proxy}/https://api.github.com/repos/aiprodcoder/MIXAPI/releases/latest"
|
|
|
- wget -qO- --timeout=5 --tries=1 "$test_url" >/dev/null 2>&1
|
|
|
- return $?
|
|
|
+ local target_url=$2
|
|
|
+
|
|
|
+ if [ "$proxy" = "direct" ]; then
|
|
|
+ echo "$target_url"
|
|
|
+ else
|
|
|
+ # 检查代理是否以 / 结尾
|
|
|
+ case "$proxy" in
|
|
|
+ */)
|
|
|
+ echo "${proxy}${target_url}"
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ echo "${proxy}/${target_url}"
|
|
|
+ ;;
|
|
|
+ esac
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
-# 获取可用的代理
|
|
|
-get_working_proxy() {
|
|
|
- for proxy in $GITHUB_PROXY_LIST; do
|
|
|
- echo "测试代理: $proxy" >&2
|
|
|
- if test_proxy "$proxy"; then
|
|
|
- echo "代理可用: $proxy" >&2
|
|
|
- echo "$proxy"
|
|
|
- return 0
|
|
|
- fi
|
|
|
- echo "代理不可用: $proxy" >&2
|
|
|
- done
|
|
|
- echo ""
|
|
|
+# 测试代理是否可用(快速检测,3秒超时)
|
|
|
+test_proxy() {
|
|
|
+ local proxy=$1
|
|
|
+ local test_url=$(build_proxy_url "$proxy" "$GITHUB_API_URL")
|
|
|
+ echo "测试: $test_url" >&2
|
|
|
+ local result=$(wget -qO- --timeout=3 --tries=1 "$test_url" 2>/dev/null)
|
|
|
+ if echo "$result" | grep -q '"tag_name"'; then
|
|
|
+ return 0
|
|
|
+ fi
|
|
|
return 1
|
|
|
}
|
|
|
|
|
|
-# 获取最新版本号(带重试机制,快速超时)
|
|
|
+# 获取最新版本号(带快速失败机制)
|
|
|
get_latest_version() {
|
|
|
local proxy
|
|
|
for proxy in $GITHUB_PROXY_LIST; do
|
|
|
- local api_url="${proxy}/https://api.github.com/repos/aiprodcoder/MIXAPI/releases/latest"
|
|
|
+ local api_url=$(build_proxy_url "$proxy" "$GITHUB_API_URL")
|
|
|
echo "尝试获取版本: $api_url" >&2
|
|
|
- local version=$(wget -qO- --timeout=8 --tries=1 "$api_url" 2>/dev/null | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p')
|
|
|
+ local response=$(wget -qO- --timeout=5 --tries=1 "$api_url" 2>/dev/null)
|
|
|
+ local version=$(echo "$response" | sed -n 's/.*"tag_name":[[:space:]]*"\([^"]*\)".*/\1/p')
|
|
|
if [ -n "$version" ]; then
|
|
|
# 保存可用的代理供后续使用
|
|
|
WORKING_PROXY="$proxy"
|
|
|
@@ -86,13 +104,13 @@ download_version() {
|
|
|
fi
|
|
|
|
|
|
local filename="mixapi-${version}-${arch_suffix}"
|
|
|
- local github_path="https://github.com/aiprodcoder/MIXAPI/releases/download/${version}/${filename}"
|
|
|
+ local github_url="${GITHUB_DOWNLOAD_BASE}/${version}/${filename}"
|
|
|
|
|
|
# 如果之前已经找到可用代理,优先使用
|
|
|
if [ -n "$WORKING_PROXY" ]; then
|
|
|
- local url="${WORKING_PROXY}/${github_path}"
|
|
|
+ local url=$(build_proxy_url "$WORKING_PROXY" "$github_url")
|
|
|
echo "下载地址: ${url}"
|
|
|
- wget -qO "$target" --timeout=30 --tries=2 "$url" 2>/dev/null
|
|
|
+ wget -qO "$target" --timeout=60 --tries=2 "$url" 2>/dev/null
|
|
|
if [ $? -eq 0 ] && [ -s "$target" ]; then
|
|
|
chmod +x "$target"
|
|
|
return 0
|
|
|
@@ -105,7 +123,7 @@ download_version() {
|
|
|
# 跳过已经失败的首选代理
|
|
|
[ "$proxy" = "$WORKING_PROXY" ] && continue
|
|
|
|
|
|
- local url="${proxy}/${github_path}"
|
|
|
+ local url=$(build_proxy_url "$proxy" "$github_url")
|
|
|
echo "尝试下载: ${url}"
|
|
|
wget -qO "$target" --timeout=30 --tries=1 "$url" 2>/dev/null
|
|
|
|