Files
SingboxForPanel/transit2minio.sh
2026-04-16 21:55:49 +08:00

62 lines
1.2 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -e
DEST="myminio/downloads/singbox"
echo "请输入 Gitea Actions 编译好的 zip 文件路径本地路径或URL"
read -r FILE
# mc 检查
if ! command -v mc >/dev/null 2>&1; then
echo "错误mc 未安装"
exit 1
fi
# unzip 检查
if ! command -v unzip >/dev/null 2>&1; then
echo "错误unzip 未安装"
exit 1
fi
# 如果是 URL先下载
if [[ "$FILE" =~ ^https?:// ]]; then
echo "检测到 URL开始下载..."
TMP_ZIP="/tmp/$(basename "$FILE")"
curl -L "$FILE" -o "$TMP_ZIP"
FILE="$TMP_ZIP"
fi
# 校验文件
if [[ ! -f "$FILE" ]]; then
echo "错误:文件不存在 -> $FILE"
exit 1
fi
# 创建临时解压目录
TMP_DIR=$(mktemp -d)
echo "解压到:$TMP_DIR"
unzip -q "$FILE" -d "$TMP_DIR"
# 找到解压后的第一层目录(兼容 zip 内有/无顶层目录)
cd "$TMP_DIR"
# 如果只有一个目录,就进入它
FIRST_DIR=$(ls -1 | head -n 1)
if [[ -d "$FIRST_DIR" ]]; then
TARGET_DIR="$TMP_DIR/$FIRST_DIR"
else
TARGET_DIR="$TMP_DIR"
fi
echo "开始上传目录内容到 MinIO$DEST"
# 复制目录内所有内容(不是整个文件夹)
mc cp --recursive "$TARGET_DIR/" "$DEST/"
echo "上传完成 ✅"
# 清理
rm -rf "$TMP_DIR"