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.
13 --user $USER:$
($PW_COMMAND) \
14 "$HOST/remote.php/dav/files/$USER/${DATA[1]}" \
16 --data '<?xml version="1.0" encoding="UTF-8"?>
17 <d:propfind xmlns:d="DAV:">
22 |
awk '/HTTP\// {if ($2 == "207") { exit 1; } else { exit 0; }}' \
24 --user $USER:$
($PW_COMMAND) \
25 -X MKCOL
"$HOST/remote.php/dav/files/$USER/${DATA[1]}"
26 # Download the media we were sent from the URI.
27 # Upload it to Nextcloud and respond with the ID in the database
28 # so that we can record success.
29 IDENTIFIER
=$
(echo ${DATA[2]} |
awk -F/ '{print $NF}')
31 --location ${DATA[2]} \
33 --user $USER:$
($PW_COMMAND) \
35 "$HOST/remote.php/dav/files/$USER/${DATA[1]}/$IDENTIFIER.jpg" && echo ${DATA[0]} received.