-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathadd-construct.sh
More file actions
executable file
·142 lines (130 loc) · 3.59 KB
/
add-construct.sh
File metadata and controls
executable file
·142 lines (130 loc) · 3.59 KB
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
#!/usr/bin/env bash
set -eo pipefail
print_usage()
{
printf "Creates a SPARQL CONSTRUCT query.\n"
printf "\n"
printf "Usage: %s options TARGET_URI\n" "$0"
printf "\n"
printf "Options:\n"
printf " -f, --cert-pem-file CERT_FILE .pem file with the WebID certificate of the agent\n"
printf " -p, --cert-password CERT_PASSWORD Password of the WebID certificate\n"
printf " -b, --base BASE_URI Base URI of the application\n"
printf " --proxy PROXY_URL The host this request will be proxied through (optional)\n"
printf "\n"
printf " --title TITLE Title of the query\n"
printf " --description DESCRIPTION Description of the query (optional)\n"
printf " --uri URI URI of the query (optional)\n"
printf "\n"
printf " --query-file ABS_PATH Absolute path to the text file with the SPARQL query string\n"
printf " --service SERVICE_URI URI of the SPARQL service specific to this query (optional)\n"
}
hash turtle 2>/dev/null || { echo >&2 "turtle not on \$PATH. Aborting."; exit 1; }
args=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-f|--cert-pem-file)
cert_pem_file="$2"
shift # past argument
shift # past value
;;
-p|--cert-password)
cert_password="$2"
shift # past argument
shift # past value
;;
-b|--base)
base="$2"
shift # past argument
shift # past value
;;
--proxy)
proxy="$2"
shift # past argument
shift # past value
;;
--title)
title="$2"
shift # past argument
shift # past value
;;
--description)
description="$2"
shift # past argument
shift # past value
;;
--uri)
uri="$2"
shift # past argument
shift # past value
;;
--query-file)
query_file="$2"
shift # past argument
shift # past value
;;
--service)
service="$2"
shift # past argument
shift # past value
;;
*) # unknown arguments
args+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${args[@]}" # restore args
target="$1"
if [ -z "$cert_pem_file" ] ; then
print_usage
exit 1
fi
if [ -z "$cert_password" ] ; then
print_usage
exit 1
fi
if [ -z "$base" ] ; then
print_usage
exit 1
fi
if [ -z "$title" ] ; then
print_usage
exit 1
fi
if [ -z "$query_file" ] ; then
print_usage
exit 1
fi
query=$(<"$query_file") # read query string from file
args+=("-f")
args+=("$cert_pem_file")
args+=("-p")
args+=("$cert_password")
args+=("-t")
args+=("text/turtle") # content type
if [ -n "$proxy" ]; then
args+=("--proxy")
args+=("$proxy")
fi
if [ -n "$uri" ] ; then
subject="<${uri}>"
else
subject="_:subject"
fi
turtle+="@prefix ldh: <https://w3id.org/atomgraph/linkeddatahub#> .\n"
turtle+="@prefix dct: <http://purl.org/dc/terms/> .\n"
turtle+="@prefix sp: <http://spinrdf.org/sp#> .\n"
turtle+="${subject} a sp:Construct .\n"
turtle+="${subject} dct:title \"${title}\" .\n"
turtle+="${subject} sp:text \"\"\"${query}\"\"\" .\n"
if [ -n "$service" ] ; then
turtle+="${subject} ldh:service <${service}> .\n"
fi
if [ -n "$description" ] ; then
turtle+="${subject} dct:description \"${description}\" .\n"
fi
# submit Turtle doc to the server
echo -e "$turtle" | turtle --base="$target" | post.sh "${args[@]}"