-
Notifications
You must be signed in to change notification settings - Fork 202
/
upload.sh
executable file
·176 lines (142 loc) · 3.48 KB
/
upload.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh
. $LKP_SRC/lib/env.sh
is_local_server()
{
[ "$LKP_SERVER" != "${LKP_SERVER#inn}" ] && return
[ "$LKP_SERVER" != "${LKP_SERVER#192.168.}" ] && return
return 1
}
upload_files_rsync()
{
[ -n "$target_directory" ] && {
local current_dir=$(pwd)
local tmpdir=$(mktemp -d)
cd "$tmpdir"
mkdir -p ${target_directory}
rsync -a --no-owner --no-group \
--chmod=D775,F664 \
--ignore-missing-args \
--min-size=1 \
${target_directory%%/*} rsync://$LKP_SERVER$JOB_RESULT_ROOT/
local JOB_RESULT_ROOT=$JOB_RESULT_ROOT/$target_directory
cd $current_dir
rm -fr "$tmpdir"
}
rsync -a --no-owner --no-group \
--chmod=D775,F664 \
--ignore-missing-args \
--min-size=1 \
"$@" rsync://$LKP_SERVER$JOB_RESULT_ROOT/
}
upload_files_lftp()
{
local file
local dest_file
local ret=0
local LFTP_TIMEOUT='set net:timeout 2; set net:reconnect-interval-base 2; set net:max-retries 2;'
local UPLOAD_HOST="http://$LKP_SERVER"
[ -n "$target_directory" ] && {
local JOB_RESULT_ROOT=$JOB_RESULT_ROOT/$target_directory
lftp -c "$LFTP_TIMEOUT; open '$UPLOAD_HOST'; mkdir -p '$JOB_RESULT_ROOT'"
}
for file
do
if [ -d "$file" ]; then
[ "$(ls -A $file)" ] && lftp -c "$LFTP_TIMEOUT; open '$UPLOAD_HOST'; mirror -R '$file' '$JOB_RESULT_ROOT/'" || ret=$?
else
[ -s "$file" ] || continue
dest_file=$JOB_RESULT_ROOT/$(basename $file)
lftp -c "$LFTP_TIMEOUT; open '$UPLOAD_HOST'; put -c '$file' -o '$dest_file'" || ret=$?
fi
done
return $ret
}
upload_one_curl()
{
local src=$1
local dest=$2
if [ -d "$src" ]; then
(
cd $(dirname "$1")
dir=$(basename "$1")
find "$dir" -type d -exec curl -sSf -X MKCOL "http://$LKP_SERVER$dest/{}" \;
find "$dir" -type f -size +0 -exec curl -sSf -T '{}' "http://$LKP_SERVER$dest/{}" \;
)
else
[ -s "$src" ] || return
curl -sSf -T "$src" http://$LKP_SERVER$dest/
fi
}
upload_files_curl()
{
local file
local ret=0
# "%" character as special character not be allowed in the URL when use curl command to transfer files, details can refer to below:
# https://www.werockyourweb.com/url-escape-characters/
local job_result_root=$(echo $JOB_RESULT_ROOT | sed 's/%/%25/g')
[ -n "$target_directory" ] && {
local dir
for dir in $(echo $target_directory | tr '/' ' ')
do
job_result_root=$job_result_root/$dir
curl -sSf -X MKCOL http://$LKP_SERVER$job_result_root >/dev/null
done
}
for file
do
upload_one_curl "$file" "$job_result_root" >/dev/null || ret=$?
done
return $ret
}
upload_files_copy()
{
local RESULT_ROOT="$RESULT_ROOT/$target_directory"
mkdir -p $RESULT_ROOT
[ "$LKP_LOCAL_RUN" != "1" ] && {
[ -n "$target_directory" ] && {
chown -R lkp.lkp $RESULT_ROOT
chmod -R g+w $RESULT_ROOT
}
chown -R lkp.lkp "$@"
chmod -R ug+w "$@"
}
local file
local ret=0
for file
do
[ -s "$file" ] || continue
cp -a "$file" $RESULT_ROOT/ || {
ls -l "$@" $RESULT_ROOT 2>&1
ret=$?
}
done
return $ret
}
upload_files()
{
if [ "$1" = "-t" ]; then
local target_directory="$2"
shift 2
fi
[ $# -ne 0 ] || return
if [ -z "$NO_NETWORK$VM_VIRTFS" ]; then
if has_cmd rsync && is_local_server; then
upload_files_rsync "$@"
return
fi
if has_cmd lftp; then
upload_files_lftp "$@"
return
fi
if has_cmd curl; then
upload_files_curl "$@"
return
fi
else
# NFS is the last resort -- it seems unreliable, either some
# content has not reached NFS server during post processing, or
# some files occasionally contain some few '\0' bytes.
upload_files_copy "$@"
return
fi
}