From 58c787a47ddfcd526efed27ec54230154d7b7640 Mon Sep 17 00:00:00 2001 From: Jacob Casper Date: Sun, 5 Apr 2020 14:36:22 -0500 Subject: [PATCH] Improve bash formatting --- listener.sh | 13 ++++++++++--- send.sh | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/listener.sh b/listener.sh index 182842e..040118a 100755 --- a/listener.sh +++ b/listener.sh @@ -8,12 +8,19 @@ while IFS='|' read -a DATA DATA_STR; do # WebDAV responds to a PROPFIND with a 207 if a resource exists. # It responds 404 otherwise, but we will attempt to create on any other code. # AWK exits with inverted exit codes to use the && bash short circuit. - curl --silent --include --user $USER:$($PW_COMMAND) "$HOST/remote.php/dav/files/$USER/${DATA[1]}" -X PROPFIND --data ' + curl --silent \ + --include \ + --user $USER:$($PW_COMMAND) \ + "$HOST/remote.php/dav/files/$USER/${DATA[1]}" \ + -X PROPFIND \ + --data ' - + - ' | awk '/HTTP\// {if ($2 == "207") { exit 1; } else { exit 0; } }' && curl --silent \ + ' \ + | awk '/HTTP\// {if ($2 == "207") { exit 1; } else { exit 0; }}' \ + && curl --silent \ --user $USER:$($PW_COMMAND) \ -X MKCOL "$HOST/remote.php/dav/files/$USER/${DATA[1]}" # Download the media we were sent from the URI. diff --git a/send.sh b/send.sh index b2e0e73..a1af21f 100755 --- a/send.sh +++ b/send.sh @@ -1,2 +1,7 @@ #!/bin/bash -sqlite3 mercuryms.sqlite "$(awk 'BEGIN {print "PRAGMA FOREIGN_KEYS = ON;"} /received/ {print "INSERT INTO SENT_MEDIA (MEDIA_ID) VALUES("$1");";}' <(sqlite3 mercuryms.sqlite "SELECT ID, PHONE_NUMBER, URI FROM MEDIA WHERE ID NOT IN (SELECT MEDIA_ID FROM SENT_MEDIA)" | timeout $TIMEOUT_SECONDS netcat $HOST $PORT))" +sqlite3 mercuryms.sqlite " +$(awk 'BEGIN {print "PRAGMA FOREIGN_KEYS = ON;"} \ + /received/ {print "INSERT INTO SENT_MEDIA (MEDIA_ID) VALUES ("$1");";}' \ + <(sqlite3 mercuryms.sqlite "SELECT ID, PHONE_NUMBER, URI FROM MEDIA WHERE ID NOT IN (SELECT MEDIA_ID FROM SENT_MEDIA)" \ + | timeout $TIMEOUT_SECONDS netcat $HOST $PORT) +)" -- 2.20.1