-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·51 lines (45 loc) · 986 Bytes
/
test.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
#!/bin/sh
if ! which curl jq >/dev/null 2>&1; then
echo Missing dependencies.
exit 1
fi
if [ ! -f ~/.malicek ]; then
echo Malíček not configured.
echo Define user and pass variables in ~/.malicek first.
exit 2
fi
. ~/.malicek
cookies=/tmp/cookies_malicek.txt
endpoint=http://localhost:3000
if [ ! -f "${cookies}" ]; then
curl \
-c "${cookies}" \
-d '{ "user": "'${user}'", "pass": "'${pass}'" }' \
-H 'Content-Type: application/json' \
-L \
-s \
"${endpoint}/login" \
>/dev/null
fi
if [ -z "${2}" ]; then
curl \
-b "${cookies}" \
-c "${cookies}" \
-L \
-s \
"${endpoint}/${1}" \
| jq
else
curl \
-b "${cookies}" \
-c "${cookies}" \
-d "${2}" \
-H 'Content-Type: application/json' \
-L \
-s \
"${endpoint}/${1}" \
| jq
fi
if [ "${1}" = 'logout' ]; then
rm -f "${cookies}"
fi