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
| #!/bin/sh
REPO="k0baya/new-api-freebsd" DOWNLOAD_DIR="./new_api_update" EXECUTABLE="new-api" TARGET_DIR="$(pwd)"
DOWNLOAD_URL=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep "browser_download_url.*$EXECUTABLE" | cut -d '"' -f 4)
if [ -z "$DOWNLOAD_URL" ]; then echo "获取最新版本的下载链接失败,请检查仓库或网络连接。" exit 1 fi
mkdir -p "$DOWNLOAD_DIR"
curl -L -o "$DOWNLOAD_DIR/$EXECUTABLE" "$DOWNLOAD_URL"
if [ $? -ne 0 ]; then echo "下载失败,请检查网络连接或下载链接。" exit 1 fi
mv "$DOWNLOAD_DIR/$EXECUTABLE" "$TARGET_DIR"
if [ $? -ne 0 ]; then echo "移动文件失败,请检查目标目录路径和权限。" exit 1 fi
chmod +x "$TARGET_DIR/$EXECUTABLE"
rm -rf "$DOWNLOAD_DIR"
echo "更新成功!"
|