From bd6e00e5da14d8d00349c3d55c7a21efee9cec84 Mon Sep 17 00:00:00 2001 From: JesFot Date: Fri, 10 May 2019 14:41:04 +0200 Subject: [PATCH 1/3] Add first curl error checks --- autoStart.bash | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/autoStart.bash b/autoStart.bash index 47ad50d..4dea5b7 100755 --- a/autoStart.bash +++ b/autoStart.bash @@ -11,11 +11,30 @@ if ! [ -x "$(command -v jq)" ]; then exit 1 fi +temp_headers=$(mktemp) + dataOfServers=$(curl -s "${baseURL}""/client" \ -H "Authorization: Bearer $apiToken" \ -H "Content-Type: application/json" \ + -D "${temp_headers}" \ -H "Accept: Application/vnd.pterodactyl.v1+json" | jq '.data') +read STATUS < <( + echo $temp_headers | + awk '/^HTTP/ { STATUS = $2 } + END { printf("%s\n",STATUS) }' + ) + +rm -f $temp_headers + +if [[ $STATUS = 404 ]]; then + echo "The baseURL is wrong and/or cannot be accessed." + exit 1 +elif [[ $STATUS = 403 ]]; then + echo "Wrong token" + exit 1 +fi + numberOfServers=$(echo "${dataOfServers}" | jq length) for (( i=0; i < "$numberOfServers"; i++ )) @@ -32,4 +51,4 @@ do -X POST \ -d '{ "signal": "start" }' fi -done \ No newline at end of file +done From e681fdab4f4cd4b1e52408e0782451c777a2d9ea Mon Sep 17 00:00:00 2001 From: JesFot Date: Fri, 10 May 2019 14:47:52 +0200 Subject: [PATCH 2/3] Fix header file reading & build warnings --- autoStart.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autoStart.bash b/autoStart.bash index 4dea5b7..c76791a 100755 --- a/autoStart.bash +++ b/autoStart.bash @@ -19,13 +19,13 @@ dataOfServers=$(curl -s "${baseURL}""/client" \ -D "${temp_headers}" \ -H "Accept: Application/vnd.pterodactyl.v1+json" | jq '.data') -read STATUS < <( - echo $temp_headers | +read -r STATUS < <( + cat "$temp_headers" | awk '/^HTTP/ { STATUS = $2 } END { printf("%s\n",STATUS) }' ) -rm -f $temp_headers +rm -f "$temp_headers" if [[ $STATUS = 404 ]]; then echo "The baseURL is wrong and/or cannot be accessed." From 5e93fe2e2da372abe512cbd179c3f3f0679d4701 Mon Sep 17 00:00:00 2001 From: JesFot Date: Fri, 10 May 2019 14:57:28 +0200 Subject: [PATCH 3/3] Fix SC2002: Useless use of cat https://github.com/koalaman/shellcheck/wiki/SC2002 --- autoStart.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/autoStart.bash b/autoStart.bash index c76791a..02f824d 100755 --- a/autoStart.bash +++ b/autoStart.bash @@ -20,9 +20,8 @@ dataOfServers=$(curl -s "${baseURL}""/client" \ -H "Accept: Application/vnd.pterodactyl.v1+json" | jq '.data') read -r STATUS < <( - cat "$temp_headers" | awk '/^HTTP/ { STATUS = $2 } - END { printf("%s\n",STATUS) }' + END { printf("%s\n",STATUS) }' < "$temp_headers" ) rm -f "$temp_headers"