/
fuseki-functions.sh
94 lines (80 loc) · 2.09 KB
/
fuseki-functions.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
#!/usr/bin/env bash
#set -x
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-r | --repository)
REPOSITORY="$2"
shift # past argument
shift # past value
;;
-u | --username)
USER_NAME="$2"
shift # past argument
shift # past value
;;
-p | --password)
PASSWORD="$2"
shift # past argument
shift # past value
;;
-h | --host)
HOST="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
FILE="$1"
if [[ -z "${REPOSITORY}" ]]; then
REPOSITORY="knora-test"
fi
if [[ -z "${HOST}" ]]; then
HOST="localhost:3030"
fi
if [[ -z "${USER_NAME}" ]]; then
USER_NAME="admin"
fi
if [[ -z "${PASSWORD}" ]]; then
PASSWORD="test"
fi
delete-repository() {
STATUS=$(curl -s -o /dev/null -w '%{http_code}' -u ${USER_NAME}:${PASSWORD} -X DELETE http://${HOST}/\$/datasets/${REPOSITORY})
if [ "${STATUS}" -eq 200 ]; then
echo "==> delete repository done"
return 0
else
echo "==> delete repository failed"
return 1
fi
}
create-repository() {
REPOSITORY_CONFIG=$(sed "s/@REPOSITORY@/${REPOSITORY}/g" ./fuseki-repository-config.ttl.template)
STATUS=$(curl -s -o /dev/null -w '%{http_code}' -u ${USER_NAME}:${PASSWORD} -H "Content-Type:text/turtle; charset=utf-8" --data-raw "${REPOSITORY_CONFIG}" -X POST http://${HOST}/\$/datasets)
if [ "${STATUS}" -eq 200 ]; then
echo "==> create repository done"
return 0
else
echo "==> create repository failed"
return 1
fi
}
upload-graph() {
STATUS=$(curl -s -o /dev/null -w '%{http_code}' -u ${USER_NAME}:${PASSWORD} -H "Content-Type:text/turtle; charset=utf-8" --data-binary @$1 -X PUT http://${HOST}/${REPOSITORY}/data\?graph\="$2")
if [ "${STATUS}" -eq 201 ]; then
echo "==> 201 Created: $1 -> $2"
return 0
elif [ "${STATUS}" -eq 200 ]; then
echo "==> 200 OK: $1 -> $2"
return 0
else
echo "==> failed with status code ${STATUS}: $1 -> $2"
return 1
fi
}