-
Notifications
You must be signed in to change notification settings - Fork 0
/
out
executable file
·342 lines (303 loc) · 9.72 KB
/
out
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/bin/bash
set -euo pipefail
clearup ()
{
rm -f /tmp/source-setup-commands.sh /tmp/params-setup-commands.sh
}
trap clearup EXIT INT TERM
exec 3>&1
exec 1>&2
payload="$(cat <&0)"
if [ "$0" = '/opt/resource/check' ]; then
echo '[{"digest":"sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}]' >&3
exit
elif [ "$0" = '/opt/resource/in' ]; then
cd "$1"
if [ "$(jq -r '.params | has("skip") // false' <<< "$payload")" = 'true' ]; then
skip="true"
else
skip="false"
fi
max_depth=$(jq -r '.params | has("max_depth") // 2' <<< "$payload")
log=$(jq -r '.version.log // ""' <<< "$payload")
if [ "$skip" = "false" ] && [ -n "$log" ]; then
case "$log" in
(https://paste.ubuntu.com/p/*)
curl -fsSL "$log" | grep -A 999999999 '<div class="paste"><pre>' | grep -B 999999999 "^</pre>" | sed -e "s/.*<pre><span><\/span>//" -e "s/^<\/pre>.*//" > log.log
echo "$log" > log.link
;;
(https://paste.debian.net/*)
curl -fsSL "$log" | grep -A 999999999 '<div class="highlight"><pre>' | grep -B 999999999 "^</pre>" | sed -e "s/.*<pre><span><\/span>//" -e "s/^<\/pre>.*//" > log.log
echo "$log" > log.link
;;
esac
fi
summary=$(jq -r '.version.summary // ""' <<< "$payload")
if [ "$skip" = "false" ] && [ -n "$summary" ]; then
case "$summary" in
(https://paste.ubuntu.com/p/*)
curl -fsSL "$summary" | grep -A 999999999 '<div class="paste"><pre>' | grep -B 999999999 "^</pre>" | sed -e "s/.*<pre><span><\/span>//" -e "s/^<\/pre>.*//" > summary.log
echo "$summary" > summary.link
;;
(https://paste.debian.net/*)
curl -fsSL "$summary" | grep -A 999999999 '<div class="highlight"><pre>' | grep -B 999999999 "^</pre>" | sed -e "s/.*<pre><span><\/span>//" -e "s/^<\/pre>.*//" > summary.log
echo "$summary" > summary.link
;;
esac
fi
package=$(jq -r .version.package <<< "$payload")
version=$(jq -r .version.version <<< "$payload")
url=$(jq -r '.version.url // ""' <<< "$payload")
if [ -n "$url" ]; then
TARGET=$(basename "$url")
echo "$url" >> "$TARGET".link
fi
WEBDAV="$(jq -r '.source.webdav // ""' <<< "$payload")"
USERNAME="$(jq -r '.source.username // ""' <<< "$payload")"
PASSWORD="$(jq -r '.source.password // ""' <<< "$payload")"
if [ "$skip" = "false" ] && [ -n "$WEBDAV" ] && [ -n "$url" ]; then
apt-get install --yes rclone
mkdir -p ~/.config/rclone
cat > ~/.config/rclone/rclone.conf <<ENDLINE
[remote]
type = webdav
url = $WEBDAV
vendor = other
user = $USERNAME
pass = $(rclone obscure "$PASSWORD")
ENDLINE
args=(-P -L --ignore-times --max-depth="$max_depth")
rclone copy "${args[@]}" remote:"$TARGET" .
fi
if [ -z "$url" ]; then
json=$(cat <<ENDLINE
{
"version": $(jq -c -M '.version' <<< "$payload"),
"metadata": [
{"name": "$package", "value": "$version"}
]
}
ENDLINE
)
else
json=$(cat <<ENDLINE
{
"version": $(jq -c -M '.version' <<< "$payload"),
"metadata": [
{"name": "$package", "value": "$version"},
{"name": "url", "value": "$url"}
]
}
ENDLINE
)
fi
jq -n "$json" >&3
exit
fi
cd "$1"
if [ "$(jq -r '.params | has("path")' <<< "$payload")" = 'true' ]; then
path=$(jq -r .params.path <<< "$payload")
else
echo "You need to provide the path."
exit 1
fi
if [ "$(jq -r '.source | has("pastebin")' <<< "$payload")" = 'true' ]; then
PASTEBIN=1
cat > ~/.pastebinit.xml <<ENDLINE
<pastebinit>
<pastebin>$(jq -r .source.pastebin <<< "$payload")</pastebin>
<author>$(jq -r .source.author <<< "$payload")</author>
<format>$(jq -r .source.format <<< "$payload")</format>
</pastebinit>
ENDLINE
else
PASTEBIN=
fi
WEBDAV="$(jq -r '.source.webdav // ""' <<< "$payload")"
USERNAME="$(jq -r '.source.username // ""' <<< "$payload")"
PASSWORD="$(jq -r '.source.password // ""' <<< "$payload")"
cd "$path"
debian=$(jq -r '.params.debian // ""' <<< "$payload")
if [ -n "$debian" ]; then
if [ -d "../$debian/debian" ]; then
rm -fr debian
cp -rv "../$debian/debian" .
elif [ -f "../$debian/changelog" ] && [ -f "../$debian/control" ] && [ -f "../$debian/copyright" ] && [ -f "../$debian/rules" ]; then
rm -fr debian
mkdir debian
cp -rv "../$debian/*" debian
else
echo "$debian is not a Debian packaging folder."
exit 1
fi
fi
SOURCE="$(dpkg-parsechangelog --show-field Source -l debian/changelog)"
VERSION="$(dpkg-parsechangelog --show-field Version -l debian/changelog)"
if [ -d .git ]; then
apt-get install --yes git
SHA=-$(git rev-parse --short HEAD)
else
SHA=""
fi
series="$(lsb_release -cs)"
if [ "$(jq -r '.params | has("args")' <<< "$payload")" = 'true' ]; then
mapfile -t ARGS < <(jq -r '.params.args|.[]' <<< "$payload")
else
ARGS=("--apt-upgrade" "--quiet")
fi
TARGET="$SOURCE-$VERSION$SHA-in-linux-container-$series"
ARGS+=("--summary-file=$TARGET-summary.log")
ARGS+=("--log-file=$TARGET-complete.log")
ARGS+=("--output-dir=$TARGET")
if [ "$(jq -r '.source | has("setup-commands")' <<< "$payload")" = 'true' ]; then
jq -r '.source."setup-commands"' <<< "$payload" > /tmp/source-setup-commands.sh
chmod +x /tmp/source-setup-commands.sh
ARGS+=("--setup-commands=/tmp/source-setup-commands.sh")
fi
if [ "$(jq -r '.params | has("setup-commands")' <<< "$payload")" = 'true' ]; then
jq -r '.params."setup-commands"' <<< "$payload" > /tmp/params-setup-commands.sh
chmod +x /tmp/params-setup-commands.sh
ARGS+=("--setup-commands=/tmp/params-setup-commands.sh")
fi
if [ "$(jq -r '.source | has("env")' <<< "$payload")" = 'true' ]; then
while read -r key; do
value=$(jq -r ".source.env.\"$key\"" <<< "$payload")
ARGS+=("--env=$key=$value")
done < <(jq -r '.source.env | keys[]' <<< "$payload")
fi
if [ "$(jq -r '.params | has("env")' <<< "$payload")" = 'true' ]; then
while read -r key; do
value=$(jq -r ".params.env.\"$key\"" <<< "$payload")
ARGS+=("--env=$key=$value")
done < <(jq -r '.params.env | keys[]' <<< "$payload")
fi
if [ "$(jq -r '.params."isolation-machine" // false' <<< "$payload")" = 'true' ]; then
:
elif [ "$(jq -r '.source."isolation-machine" // false' <<< "$payload")" = 'true' ]; then
:
else
if grep 'isolation-machine' /usr/bin/autopkgtest-virt-null | grep ,$ >/dev/null; then
sed -i "/'isolation-machine',/d" /usr/bin/autopkgtest-virt-null
else
sed -i "s/'isolation-machine'//" /usr/bin/autopkgtest-virt-null
fi
fi
if autopkgtest "${ARGS[@]}" -- null; then
RESULT="$?"
else
RESULT="$?"
fi
if [ -n "$PASTEBIN" ]; then
apt-get install --yes pastebinit
log=$(cat "$TARGET-complete.log" | pastebinit)
echo "full log: $log" >> "$TARGET-summary.log"
summary=$(cat "$TARGET-summary.log" | pastebinit)
url="$summary"
fi
if [ -n "$WEBDAV" ]; then
apt-get install --yes rclone
mkdir -p ~/.config/rclone
cat > ~/.config/rclone/rclone.conf <<ENDLINE
[remote]
type = webdav
url = $WEBDAV
vendor = other
user = $USERNAME
pass = $(rclone obscure "$PASSWORD")
ENDLINE
args=(-P -L --ignore-times)
rclone copy "${args[@]}" "$TARGET-complete.log" remote:"$TARGET"
log="$WEBDAV/$TARGET/$TARGET-complete.log"
rclone copy "${args[@]}" "$TARGET-summary.log" remote:"$TARGET"
summary="$WEBDAV/$TARGET/$TARGET-summary.log"
rclone copy "${args[@]}" "$TARGET" remote:"$TARGET"
url="$WEBDAV/$TARGET"
fi
echo "=== $TARGET-summary.log ==="
cat "$TARGET-summary.log"
digest="sha256:$(cat "$TARGET-complete.log" | sha256sum | awk '{print $1}')"
if [ -n "$PASTEBIN" ] || [ -n "$WEBDAV" ]; then
json=$(cat <<ENDLINE
{
"version": {
"digest": "$digest",
"package": "$SOURCE",
"version": "$VERSION",
"log": "$log",
"summary": "$summary",
"url": "$url"
},
"metadata": [
{"name": "${SOURCE}", "value": "${VERSION}"},
{"name": "url", "value": "${url}"}
]
}
ENDLINE
)
else
json=$(cat <<ENDLINE
{
"version": {
"digest": "$digest",
"package": "$SOURCE",
"version": "$VERSION"
},
"metadata": [
{"name": "${SOURCE}", "value": "${VERSION}"}
]
}
ENDLINE
)
fi
jq -n "$json" >&3
case "$RESULT" in
(0)
echo -e "EXIT STATUS\n\t0 all tests passed"
;;
(2)
echo -e "EXIT STATUS\n\t2 at least one test was skipped (or at least one flaky test failed)"
;;
(4)
echo -e "EXIT STATUS\n\t4 at least one test failed"
;;
(6)
echo -e "EXIT STATUS\n\t6 at least one test failed and at least one test skipped"
;;
(8)
echo -e "EXIT STATUS\n\t8 no tests in this package, or all non-superficial tests were skipped"
;;
(12)
echo -e "EXIT STATUS\n\t12 erroneous package"
;;
(14)
echo -e "EXIT STATUS\n\t14 erroneous package and at least one test skipped"
;;
(16)
echo -e "EXIT STATUS\n\t16 testbed failure"
;;
(20)
echo -e "EXIT STATUS\n\t20 other unexpected failures including bad usage"
;;
(*)
echo -e "EXIT STATUS\n\t$RESULT unexpected exit status for autopkgtest"
;;
esac
DONTFAIL=$(jq -r '.params.dont_fail // false' <<< "$payload")
if [ "$(jq -r '.params | has("exit_status")' <<< "$payload")" = 'true' ]; then
mapfile -t EXITSTATUS < <(jq -r '.params.exit_status | .[]' <<< "$payload")
else
EXITSTATUS=()
fi
if [ "$DONTFAIL" = "true" ]; then
exit
fi
if [ -z "${EXITSTATUS[*]}" ]; then
exit "$RESULT"
else
for exit_status in "${EXITSTATUS[@]}"; do
if [ "${exit_status}" = "$RESULT" ]; then
exit
fi
done
exit 1
fi