From 566ebd1436fc0c19ee017a6866d1ef640e9a14c4 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Thu, 15 Apr 2021 11:13:38 +0200
Subject: [PATCH] added debugging of curl request

---
 shellscripts/getfile.sh | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/shellscripts/getfile.sh b/shellscripts/getfile.sh
index 65d1bb8..381db6c 100755
--- a/shellscripts/getfile.sh
+++ b/shellscripts/getfile.sh
@@ -6,6 +6,7 @@
 # ----------------------------------------------------------------------
 # 2021-03-31  v1.0  <axel.hahn@iml.unibe.ch>  init
 # 2021-04-13  v1.1  <axel.hahn@iml.unibe.ch>  add support for custom config
+# 2021-04-15  v1.2  <axel.hahn@iml.unibe.ch>  added debugging of curl request
 # ======================================================================
 
 # ----------------------------------------------------------------------
@@ -125,27 +126,39 @@ ${apiTS}
     myHash=`echo -n "$data" | openssl sha1 -hmac "${secret}" | cut -f 2 -d" "`
     myHash=`echo -n "$myHash" | base64`
 
+    moreheaders="--fail"
+    test $bDebug = 1 && moreheaders="-i"
+
+    tmpdownloadfile="${outfile}.downloading"
+
     curl \
       -H "Accept: application/json" -H "Content-Type: application/json" \
       -H "Date: ${apiTS}" \
       -H "Authorization: demo-bash-client:${myHash}" \
       -X $apiMethod \
-      -o "${outfile}.downloading" \
-      --fail \
+      -o "${tmpdownloadfile}" \
+      $moreheaders \
       -s \
       ${IMLCI_URL}${apiRequest}
 
-    if [ $? -eq 0 ]; then
+    rc=$?
+    if [ "$bDebug" = "1" ]; then
+        cat "${tmpdownloadfile}"
+        rm -f "${tmpdownloadfile}"
+        exit 0
+    fi
+
+    if [ $rc -eq 0 ]; then
         # echo OK.
 
         # no outfile (= request to a directory)
         if [ -z "$outfile" ]; then
             # echo
             # echo ----- RESPONSE BODY:
-            cat "${outfile}.downloading"
-            rm -f "${outfile}.downloading" 
+            cat "${tmpdownloadfile}"
+            rm -f "${tmpdownloadfile}" 
         else
-            mv "${outfile}.downloading" "${outfile}"
+            mv "${tmpdownloadfile}" "${outfile}"
             ls -l "${outfile}"
         fi
     else
@@ -155,7 +168,7 @@ ${apiTS}
     curl\
       -H "Accept: application/json" -H "Content-Type: application/json" \
       -X $apiMethod \
-      -o "${outfile}.downloading" \
+      -o "${tmpdownloadfile}" \
       ${IMLCI_URL}${apiRequest}
   fi
 
-- 
GitLab