minio_dw/upload_to_plugai.sh

49 lines
1.3 KiB
Bash
Executable File
Raw 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.

#!/bin/bash
set -e
if [ $# -lt 1 ]; then
echo "❌ 用法: $0 <本地文件路径>"
exit 1
fi
file="$1"
bucket="plugai"
host="https://s3.szaiai.com"
endpoint="https://api.szaiai.com"
access_key="admin"
secret_key="Admin@123.."
alias="autoalias"
if [ ! -f "$file" ]; then
echo "❌ 文件不存在: $file"
exit 1
fi
mc alias rm $alias 2>/dev/null || true
mc alias set $alias $endpoint $access_key $secret_key > /dev/null
mc mb --ignore-existing "$alias/$bucket" > /dev/null
filename=$(basename "$file")
echo "🚀 开始上传文件: $file"
mc cp "$file" "$alias/$bucket/$filename"
echo "✅ 上传完成,开始验证..."
# 计算上传前本地文件前 1MB 的 SHA256
local_hash=$(head -c 1048576 "$file" | sha256sum | awk '{print $1}')
# 下载远程同名文件的前 1MB 来比较(使用 Range
remote_hash=$(curl -s -H "Range: bytes=0-1048575" "$host/$bucket/$filename" | sha256sum | awk '{print $1}')
if [ "$local_hash" != "$remote_hash" ]; then
echo "❌ 验证失败:远程文件仍然是旧的,未被覆盖!"
echo "本地: $local_hash"
echo "远程: $remote_hash"
exit 1
fi
encoded=$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "$filename")
echo "🎉 文件上传并验证成功:$host/$bucket/$encoded?ts=$(date +%s)"