-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathadd-restriction.sh
More file actions
executable file
·153 lines (142 loc) · 4 KB
/
add-restriction.sh
File metadata and controls
executable file
·153 lines (142 loc) · 4 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
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash
set -eo pipefail
print_usage()
{
printf "Creates an OWL restriction.\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 admin application\n"
printf " --proxy PROXY_URL The host this request will be proxied through (optional)\n"
printf "\n"
printf " --label LABEL Label of the restriction\n"
printf " --comment COMMENT Description of the restriction (optional)\n"
printf "\n"
printf " --uri URI URI of the restriction (optional)\n"
printf " --on-property PROPERTY_URI URI of the restricted property (optional)\n"
printf " --all-values-from URI URI value of owl:allValuesFrom (optional)\n"
printf " --has-value URI URI value of owl:hasValue (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
;;
--label)
label="$2"
shift # past argument
shift # past value
;;
--comment)
comment="$2"
shift # past argument
shift # past value
;;
--uri)
uri="$2"
shift # past argument
shift # past value
;;
--on-property)
on_property="$2"
shift # past argument
shift # past value
;;
--all-values-from)
all_values_from="$2"
shift # past argument
shift # past value
;;
--has-value)
has_value="$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 "$label" ] ; then
print_usage
exit 1
fi
if [ -z "$1" ]; then
print_usage
exit 1
fi
# allow explicit URIs
if [ -n "$uri" ] ; then
restriction="<${uri}>" # URI
else
restriction="_:restriction" # blank node
fi
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
turtle+="@prefix owl: <http://www.w3.org/2002/07/owl#> .\n"
turtle+="@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
turtle+="@prefix owl: <http://www.w3.org/2002/07/owl#> .\n"
turtle+="@prefix spin: <http://spinrdf.org/spin#> .\n"
turtle+="${restriction} a owl:Restriction .\n"
turtle+="${restriction} rdfs:label \"${label}\" .\n"
if [ -n "$comment" ] ; then
turtle+="${restriction} rdfs:comment \"${comment}\" .\n"
fi
if [ -n "$on_property" ] ; then
turtle+="${restriction} owl:onProperty <$on_property> .\n"
fi
if [ -n "$all_values_from" ] ; then
turtle+="${restriction} owl:allValuesFrom <$all_values_from> .\n"
fi
if [ -n "$has_value" ] ; then
turtle+="${restriction} owl:hasValue <$has_value> .\n"
fi
# submit Turtle doc to the server
echo -e "$turtle" | turtle --base="$target" | post.sh "${args[@]}"