-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_upyun_source.sh
More file actions
executable file
·72 lines (62 loc) · 1.36 KB
/
update_upyun_source.sh
File metadata and controls
executable file
·72 lines (62 loc) · 1.36 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#填写你的Token
TOKEN="你的又拍云Token"
# 用法判断
if [ $# -ne 3 ]; then
echo "用法: $0 <BUCKET_NAME> <ip> <port>"
exit 1
fi
# 传入参数
BUCKET_NAME="$1"
ip="$2"
port="$3"
# API请求路径
API_URL="https://api.upyun.com/v2/buckets/cdn/source"
# 构造 JSON 请求体
read -r -d '' PAYLOAD <<EOF
{
"bucket_name": "$BUCKET_NAME",
"cdn": {
"bgp": {
"servers": [
{
"host": "$ip",
"port": $port,
"weight": 1,
"max_fails": 3,
"fail_timeout": 30
}
]
}
},
"redirect_follow_num": 0,
"redirect_follow": "enable",
"ssl_verify": "disable",
"source_type": "https",
"domain_follow": "enable"
}
EOF
# 发起请求
response=$(curl -s -X POST "$API_URL" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$PAYLOAD")
# 判断结果
if echo "$response" | grep -q '"result":true'; then
echo "✅ 回源地址修改成功"
exit 0
fi
# 提取错误信息
error_type=$(echo "$response" | grep -o '"type":"[^"]*"' | cut -d':' -f2 | tr -d '"')
echo "❌ 回源地址修改失败"
case "$error_type" in
AccessDenied)
echo ",访问被拒绝,可能是 Token 无效或未授权。"
;;
BucketNotFound)
echo ",Bucket 不存在,检查 bucket 名是否拼写正确。"
;;
*)
echo "$error_type"
;;
esac