-
Notifications
You must be signed in to change notification settings - Fork 27
/
test.sh
executable file
·58 lines (42 loc) · 1.29 KB
/
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
52
53
54
55
56
57
58
#!/bin/bash
set -euo pipefail
USER="testtest"
HOST="localhost:8083"
cleanup () {
rm -f server/data.sqlite
[ -f server/data2.sqlite ] && mv server/data2.sqlite server/data.sqlite
[ -f cookies.txt ] && rm -f cookies.txt
kill $PID
}
function requote() {
local res=""
for x in "${@}" ; do
# try to figure out if quoting was required for the $x:
grep -q "[[:space:]]" <<< "$x" && res="${res} '${x}'" || res="${res} ${x}"
done
# remove first space and print:
sed -e 's/^ //' <<< "${res}"
}
trap "cleanup" ERR
[ -f server/data.sqlite ] && mv server/data.sqlite server/data2.sqlite
sqlite3 server/data.sqlite < server/inc/schema.sql
sqlite3 server/data.sqlite "INSERT INTO users (name, password) VALUES ('${USER}', '\$2y\$10\$taowFf8qdr23Rx13cblkQ.IBHcj2yB.ESR9Hb8OOEEDwkyVSxkiMe');"
php -S $HOST -t server server/index.php > /dev/null 2>&1 &
PID=$!
sleep 0.5
BASE_URL="http://${USER}:testtest@${HOST}/"
r() {
URL="$BASE_URL$1"
shift
ARGS=$(requote "${@}")
CMD="curl -s -v -c cookies.txt $ARGS $URL"
echo $CMD
$CMD
}
echo -n "Login... "
r api/2/auth/${USER}/login.json -X POST
echo -n "Create device... "
r api/2/devices/${USER}/antennapod.json -d '{"caption": "Bla bla", "type": "mobile"}' -X POST
echo -n "Logout... "
r api/2/auth/${USER}/logout.json -X POST
exit 0