-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.sh
More file actions
executable file
·83 lines (69 loc) · 2.04 KB
/
upload.sh
File metadata and controls
executable file
·83 lines (69 loc) · 2.04 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
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
### NOTE: 使用bash而不能是sh, 否则uploadFile会有signature不匹配
# ==================== Config ====================
accessKeyId="LTAI5tFNW3QivvhSM1U2zWSy"
accessKeySecret=$ALI_OSS_SECRET_HZ
endpoint="oss-cn-hangzhou.aliyuncs.com"
bucket="brainco-hz-com"
cloudFolder="docs/NeuroMaster"
# ================================================
declare -a result=()
encodeFilename=""
function uploadFile() {
path="$cloudFolder/$2"
contentType=$(file -b --mime-type "$1")
# Fix: js, css文件contentType返回text/plain
if [[ "$1" == *.js ]]; then
contentType="text/javascript"
elif [[ "$1" == *.css ]]; then
contentType="text/css"
fi
dateValue="$(TZ=GMT env LANG=en_US.UTF-8 date +"%a, %d %b %Y %H:%M:%S GMT")"
stringToSign="PUT\n\n$contentType\n$dateValue\n/$bucket/$path"
signature=$(echo -en "$stringToSign" | openssl sha1 -hmac "$accessKeySecret" -binary | base64)
# log "uploadFile, $1 => $path, $contentType"
# return
url="https://$bucket.$endpoint/$path"
curl -i -q -X PUT -T "$1" \
-H "Content-Type: $contentType" \
-H "Host: $bucket.$endpoint" \
-H "Date: $dateValue" \
-H "Authorization: OSS $accessKeyId:$signature" \
$url
result+=($url)
}
function urlEncode() {
encodeFilename=""
local length="${#1}"
for ((i = 0; i < length; i++)); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-])
encodeFilename=$encodeFilename$(printf "$c")
;;
*)
encodeFilename=$encodeFilename$(printf "$c" | xxd -p -c1 |
while read x; do
printf "%%%s" "$x"
done)
;;
esac
done
}
log() {
time=$(date "+%Y-%m-%d %H:%M:%S")
text=$1
# echo "[$time] $text"
echo "\033[42;30m [$time] $text \033[0m"
}
# build
pnpm docs:build
directory="./docs/.vuepress/dist"
# 遍历指定目录下的所有文件
find "$directory" -type f ! -name ".DS_Store" | while read -r file; do
relative_path="${file#$directory/}" # 去掉目录前缀部分
# echo "Processing file: $file $relative_path"
uploadFile $file $relative_path
# break
done
log "done"