Created
February 1, 2015 10:18
-
-
Save melvincarvalho/b92cc2d1a97f2f918d0f to your computer and use it in GitHub Desktop.
post to ldpc and acl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# init | |
#LDPC="https://localhost:8888/test/put/" | |
#LDPC="https://melvin.rww.io/workspace/blog/ch5/" | |
LDPC=$(git config webid.weblog) | |
KEYFILE=$(git config webid.keyfile) | |
WEBID=$(git config user.webid) | |
NAME=$(git config user.name) | |
DEPICTION=$(git config user.depiction) | |
USER_AGENT='User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/39.0.2171.65 Chrome/39.0.2171.65 Safari/537.36' | |
# turtle for blog post | |
T=$'\n<>\n <http://purl.org/dc/terms/created>\n "' | |
T=$T$(date -u -Iseconds) | |
T=$T$'"^^<http://www.w3.org/2001/XMLSchema#dateTime>;\n' | |
T=$T$'<http://rdfs.org/sioc/ns#content>\n "'$1 | |
T=$T$'";\n <http://rdfs.org/sioc/ns#has_creator>\n ' | |
T=$T$'<#author>;\n a <http://rdfs.org/sioc/ns#Post>.\n' | |
T=$T$'<#author>\n <http://rdfs.org/sioc/ns#account_of>\n ' | |
T=$T$'<'$WEBID$'>;\n <http://rdfs.org/sioc/ns#avatar>\n ' | |
T=$T$'<'$DEPICTION$'>;\n a ' | |
T=$T$'<http://rdfs.org/sioc/ns#UserAccount>;\n ' | |
T=$T$'<http://xmlns.com/foaf/0.1/name>\n "'$NAME$'".\n' | |
# post blog and get location | |
LOC=$(curl --key "$KEYFILE" --cert $KEYFILE -k -v "$LDPC" -H "$USER_AGENT" -H 'Content-Type: text/turtle' -H 'Accept: */*' -H 'Connection: keep-alive' --data-binary "$T" 2>&1 | grep Location: | sed 's/.*Location: \(.*\)/\1/' | dos2unix ) | |
# get ACL URI | |
ACL=$(echo $LOC | sed 's/^\(.*\)\/\(.*\)/\1\/.acl.\2/' ) | |
echo $ACL | |
# turtle of acl | |
T=$'\n<#owner>\n a <http://www.w3.org/ns/auth/acl#Authorization>;\n' | |
T=$T$' <http://www.w3.org/ns/auth/acl#accessTo>\n ' | |
T=$T$'<>, <'$LOC$'>;\n ' | |
T=$T$'<http://www.w3.org/ns/auth/acl#agent>\n <'$WEBID$'>;\n ' | |
T=$T$'<http://www.w3.org/ns/auth/acl#mode>\n ' | |
T=$T$'<http://www.w3.org/ns/auth/acl#Control>,\n ' | |
T=$T$'<http://www.w3.org/ns/auth/acl#Read>,\n ' | |
T=$T$'<http://www.w3.org/ns/auth/acl#Write>.\n' | |
# put acl | |
curl -k --key "$KEYFILE" --cert $KEYFILE "$ACL" -X PUT -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H "$USER_AGENT" -H 'Content-Type: text/turtle' -H 'Accept: */*' -H 'Connection: keep-alive' --data-binary "$T" --compressed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment