2 # DATA indices are defined by the mercuryms-send program, and are from mercuryms-sqlite
4 # 1: MEDIA.PHONE_NUMBER
6 while IFS
='|' read -a DATA DATA_STR
; do
7 # Check if the phone number has an existing folder.
8 # WebDAV responds to a PROPFIND with a 207 if a resource exists.
9 # It responds 404 otherwise, but we will attempt to create on any other code.
10 # AWK exits with inverted exit codes to use the && bash short circuit.
11 curl
--silent --include --user $USER:$
($PW_COMMAND) "$HOST/remote.php/dav/files/$USER/${DATA[1]}" -X PROPFIND
--data '<?xml version="1.0" encoding="UTF-8"?>
12 <d:propfind xmlns:d="DAV:">
13 <d:prop xmlns:oc="http://owncloud.org/ns">
16 </d:propfind>' |
awk '/HTTP\// {if ($2 == "207") { exit 1; } else { exit 0; } }' && curl
--silent \
17 --user $USER:$
($PW_COMMAND) \
18 -X MKCOL
"$HOST/remote.php/dav/files/$USER/${DATA[1]}"
19 # Download the media we were sent from the URI.
20 # Upload it to Nextcloud and respond with the ID in the database
21 # so that we can record success.
22 IDENTIFIER
=$
(echo ${DATA[2]} |
awk -F/ '{print $NF}')
24 --location ${DATA[2]} \
26 --user $USER:$
($PW_COMMAND) \
28 "$HOST/remote.php/dav/files/$USER/${DATA[1]}/$IDENTIFIER.jpg" && echo ${DATA[0]} received.