From ead031caa021f7dad8d599a9d8b5e4ef5f608eab Mon Sep 17 00:00:00 2001 From: folex <0xdxdy@gmail.com> Date: Sun, 18 Aug 2019 13:48:45 +0300 Subject: [PATCH] Handle absence of jq & base64 --- backend-assemblyscript/step0-framework/run.sh | 3 ++- backend-assemblyscript/step1-json-api/run.sh | 3 ++- backend-assemblyscript/step2-database-only/run.sh | 3 ++- backend-assemblyscript/step3-finished-app/run.sh | 14 ++++++++++++-- backend-rust/step0-framework/run.sh | 3 ++- backend-rust/step1-json-api/run.sh | 2 +- backend-rust/step2-database-only/run.sh | 3 ++- backend-rust/step3-finished-app/run.sh | 6 ++++-- 8 files changed, 27 insertions(+), 10 deletions(-) diff --git a/backend-assemblyscript/step0-framework/run.sh b/backend-assemblyscript/step0-framework/run.sh index ac48dd0..880949e 100755 --- a/backend-assemblyscript/step0-framework/run.sh +++ b/backend-assemblyscript/step0-framework/run.sh @@ -27,7 +27,8 @@ echo -e "Sending request: $REQUEST" echo "curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$REQUEST" --compressed" echo -RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$REQUEST" --compressed | jq -r .result.data | base64 -D) +RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$REQUEST" --compressed) +RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE") echo -e "$RESPONSE\n" diff --git a/backend-assemblyscript/step1-json-api/run.sh b/backend-assemblyscript/step1-json-api/run.sh index bf32b9a..28c98bc 100755 --- a/backend-assemblyscript/step1-json-api/run.sh +++ b/backend-assemblyscript/step1-json-api/run.sh @@ -30,7 +30,8 @@ JSON echo -e "Sending request... $JSON" # Send json as a request, and receive result -RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 -D) +RESPONSE=$(curl -s 'http://localhost:30000/apps/0/tx' --data $'sessionId/0\n'"$JSON" --compressed) +RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE") # Parse json or print response as is echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE" diff --git a/backend-assemblyscript/step2-database-only/run.sh b/backend-assemblyscript/step2-database-only/run.sh index 52fe18a..3d0d038 100755 --- a/backend-assemblyscript/step2-database-only/run.sh +++ b/backend-assemblyscript/step2-database-only/run.sh @@ -34,7 +34,8 @@ echo -e "Sending request: $REQUEST" echo "curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$REQUEST" --compressed" echo -RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$REQUEST" --compressed | jq -r .result.data | base64 -D) +RESPONSE=$(curl -s 'http://localhost:30000/apps/0/tx' --data $'sessionId/0\n'"$REQUEST" --compressed) +RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE") # Parse json or print response as is echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE" diff --git a/backend-assemblyscript/step3-finished-app/run.sh b/backend-assemblyscript/step3-finished-app/run.sh index dec7267..1eaccad 100755 --- a/backend-assemblyscript/step3-finished-app/run.sh +++ b/backend-assemblyscript/step3-finished-app/run.sh @@ -2,6 +2,14 @@ set -e +command -v jq >/dev/null 2>&1 || { + echo >&2 "jq is not installed, wouldn't parse responses" +} + +command -v base64 >/dev/null 2>&1 || { + echo >&2 "base64 is not installed, wouldn't parse responses" +} + mkdir -p wasm # Download SQLite @@ -43,7 +51,8 @@ JSON echo -e "Sending post: $JSON" # Send json as a request, and receive result -RESPONSE=$(curl -s 'http://localhost:30000/apps/0/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 -D) +RESPONSE=$(curl -s 'http://localhost:30000/apps/0/tx' --data $'sessionId/0\n'"$JSON" --compressed) +RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE") # Parse json or print response as is echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE" @@ -62,7 +71,8 @@ JSON echo -e "Fetching posts: $JSON" # Send json as a request, and receive result -RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/1\n'"$JSON" --compressed | jq -r .result.data | base64 -D) +RESPONSE=$(curl -s 'http://localhost:30000/apps/0/tx' --data $'sessionId/1\n'"$JSON" --compressed) +RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE") # Parse json or print response as is echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE" diff --git a/backend-rust/step0-framework/run.sh b/backend-rust/step0-framework/run.sh index c10a4de..40db6c9 100755 --- a/backend-rust/step0-framework/run.sh +++ b/backend-rust/step0-framework/run.sh @@ -26,7 +26,8 @@ echo -e "Sending request: $REQUEST" echo "curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$REQUEST" --compressed" echo -RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$REQUEST" --compressed | jq -r .result.data | base64 -D) +RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$REQUEST" --compressed) +RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE") echo -e "$RESPONSE\n" diff --git a/backend-rust/step1-json-api/run.sh b/backend-rust/step1-json-api/run.sh index d365773..13ca4fa 100755 --- a/backend-rust/step1-json-api/run.sh +++ b/backend-rust/step1-json-api/run.sh @@ -29,7 +29,7 @@ JSON echo -e "Sending request... $JSON" # Send json as a request, and receive result -RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 -D) +RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 --decode) # Parse json or print response as is echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE" diff --git a/backend-rust/step2-database-only/run.sh b/backend-rust/step2-database-only/run.sh index 551de20..ce73bcd 100755 --- a/backend-rust/step2-database-only/run.sh +++ b/backend-rust/step2-database-only/run.sh @@ -32,7 +32,8 @@ echo -e "Sending request..." echo "curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'$USER --compressed" echo -RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$USER" --compressed | jq -r .result.data | base64 -D) +RESPONSE=$(curl -s 'http://localhost:30000/apps/0/tx' --data $'sessionId/0\n'"$REQUEST" --compressed) +RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE") # Parse json or print response as is echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE" diff --git a/backend-rust/step3-finished-app/run.sh b/backend-rust/step3-finished-app/run.sh index fdfb379..11cec6c 100755 --- a/backend-rust/step3-finished-app/run.sh +++ b/backend-rust/step3-finished-app/run.sh @@ -42,7 +42,8 @@ JSON echo -e "Sending post: $JSON" # Send json as a request, and receive result -RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/0\n'"$JSON" --compressed | jq -r .result.data | base64 -D) +RESPONSE=$(curl -s 'http://localhost:30000/apps/0/tx' --data $'sessionId/0\n'"$JSON" --compressed) +RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE") # Parse json or print response as is echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE" @@ -61,7 +62,8 @@ JSON echo -e "Fetching posts: $JSON" # Send json as a request, and receive result -RESPONSE=$(curl -s 'http://localhost:30000/apps/1/tx' --data $'sessionId/1\n'"$JSON" --compressed | jq -r .result.data | base64 -D) +RESPONSE=$(curl -s 'http://localhost:30000/apps/0/tx' --data $'sessionId/1\n'"$JSON" --compressed) +RESPONSE=$(echo "$RESPONSE" | jq -r .result.data | base64 --decode 2>/dev/null || echo "$RESPONSE") # Parse json or print response as is echo "$RESPONSE" | jq . 2>/dev/null || echo "$RESPONSE"