forked from dgl/paste.sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-misc
executable file
·37 lines (31 loc) · 931 Bytes
/
update-misc
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
#!/bin/bash
HOST=https://paste.sh
die() {
echo "${1}" >&2
exit ${2:-1}
}
# Write data to a temp file and open it on given fd to avoid passing on command
# line
tmpfd() {
tmp="$(mktemp)"
echo "$1" > "$tmp" || die "Unable to write to temp. file."
eval "exec $2<$tmp"
rm -f $tmp || die "Unable to remove temp. file. Aborting to avoid key leak"
}
for file in misc/*; do
id=$(basename $file)
if [[ $id = index ]]; then
serverkey=
else
serverkey=public
fi
clientkey=
tmpfd "${id}${serverkey}${clientkey}${HOST}" 3
tmpfile=$(mktemp)
trap 'rm -f $tmpfile' EXIT
< $file openssl enc -aes-256-cbc -md sha512 -pass fd:3 -base64 > $tmpfile
# Get rid of the temp. file once server supports HTTP/1.1 chunked uploads
curl -sS -0 -H "X-Server-Auth: $(<serverauth)" -H "X-Server-Key: ${serverkey}" \
-T $tmpfile "http://localhost:5000/${id}" || die "Failed pasting data"
echo "$HOST/${id}"
done