From b7a1594ff499d920394145e9be81efce04bd5234 Mon Sep 17 00:00:00 2001 From: cs-lee Date: Sat, 2 Dec 2017 08:51:25 -0800 Subject: [PATCH 1/5] Handle errors about third party download and extract If absolute fail to download node binary, shell script should stop and print right error log. This patch do it. Additional add one function to print red color error log. ISSUE=none --- bootstrap/common/sync_third_party.sh | 17 +++++++++++++++++ bootstrap/common/util.sh | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/bootstrap/common/sync_third_party.sh b/bootstrap/common/sync_third_party.sh index 95093cca..241dba76 100644 --- a/bootstrap/common/sync_third_party.sh +++ b/bootstrap/common/sync_third_party.sh @@ -30,6 +30,14 @@ function sync_node() { esac sync_third_party $base_url$target_url $target_path + + if [ $? -eq 2 ]; then + error_log "node download fail" + exit + elif [ $? -eq 3 ]; then + error_log "node extract fail" + exit + fi } function sync_mongodb() { @@ -45,6 +53,15 @@ function sync_mongodb() { esac sync_third_party $base_url$target_url $target_path + + if [ $? -eq 2 ]; then + error_log "mongodb download fail" + exit + elif [ $? -eq 3 ]; then + error_log "mongodb extract fail" + exit + fi + } function sync_third_party() { diff --git a/bootstrap/common/util.sh b/bootstrap/common/util.sh index c3a0a91e..ca92d3c6 100644 --- a/bootstrap/common/util.sh +++ b/bootstrap/common/util.sh @@ -81,3 +81,8 @@ function extract_archive() { return $? } + +# Print red color log. +function error_log() { + echo -e "\e[31m$1" +} From f810b84727bef8ad2c85ff4b90417abdad854df5 Mon Sep 17 00:00:00 2001 From: cs-lee Date: Mon, 4 Dec 2017 05:09:48 -0800 Subject: [PATCH 2/5] Handle errors about third party download and extract Add default color tag. ISSUE=none --- bootstrap/common/util.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/common/util.sh b/bootstrap/common/util.sh index ca92d3c6..ff986f95 100644 --- a/bootstrap/common/util.sh +++ b/bootstrap/common/util.sh @@ -84,5 +84,5 @@ function extract_archive() { # Print red color log. function error_log() { - echo -e "\e[31m$1" + echo -e "\e[31m$1\e[39m" } From e9556093054b866be1302ce446e047fac902dfc8 Mon Sep 17 00:00:00 2001 From: cs-lee Date: Mon, 4 Dec 2017 05:48:24 -0800 Subject: [PATCH 3/5] Handle errors about third party download and extract extract function return error number when invalid input is comming. ISSUE=none --- bootstrap/common/sync_third_party.sh | 10 ++++++---- bootstrap/common/util.sh | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bootstrap/common/sync_third_party.sh b/bootstrap/common/sync_third_party.sh index 241dba76..d9b19354 100644 --- a/bootstrap/common/sync_third_party.sh +++ b/bootstrap/common/sync_third_party.sh @@ -31,10 +31,11 @@ function sync_node() { sync_third_party $base_url$target_url $target_path - if [ $? -eq 2 ]; then + local result=$? + if [ $result -eq 2 ]; then error_log "node download fail" exit - elif [ $? -eq 3 ]; then + elif [ $result -eq 3 ]; then error_log "node extract fail" exit fi @@ -54,10 +55,11 @@ function sync_mongodb() { sync_third_party $base_url$target_url $target_path - if [ $? -eq 2 ]; then + local result=$? + if [ $result -eq 2 ]; then error_log "mongodb download fail" exit - elif [ $? -eq 3 ]; then + elif [ $result -eq 3 ]; then error_log "mongodb extract fail" exit fi diff --git a/bootstrap/common/util.sh b/bootstrap/common/util.sh index ff986f95..4b8ee370 100644 --- a/bootstrap/common/util.sh +++ b/bootstrap/common/util.sh @@ -77,6 +77,7 @@ function extract_archive() { case $src_path in *.tar.gz|*.tgz) tar -xvzf $src_path -C $dest_path > /dev/null 2>&1 ;; *.zip) unzip $src_path -d $dest_path > /dev/null 2>&1 ;; + *) return 3 ;; esac return $? From 6b60143b66ac0b386a7271c5234ceb1124aedd6f Mon Sep 17 00:00:00 2001 From: cs-lee Date: Tue, 5 Dec 2017 08:07:26 -0800 Subject: [PATCH 4/5] Handle errors about third party download and extract download and extract function handle error log itself. ISSUE=none --- bootstrap/common/sync_third_party.sh | 23 ++--------------------- bootstrap/common/util.sh | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/bootstrap/common/sync_third_party.sh b/bootstrap/common/sync_third_party.sh index d9b19354..7108239f 100644 --- a/bootstrap/common/sync_third_party.sh +++ b/bootstrap/common/sync_third_party.sh @@ -29,16 +29,7 @@ function sync_node() { darwin_x86_64) local target_url="/node-v6.9.5-darwin-x64.tar.gz" ;; esac - sync_third_party $base_url$target_url $target_path - - local result=$? - if [ $result -eq 2 ]; then - error_log "node download fail" - exit - elif [ $result -eq 3 ]; then - error_log "node extract fail" - exit - fi + sync_third_party $base_url$target_url $target_path || exit } function sync_mongodb() { @@ -53,17 +44,7 @@ function sync_mongodb() { darwin_x86_64) local target_url="/osx/mongodb-osx-x86_64-3.2.12.tgz" ;; esac - sync_third_party $base_url$target_url $target_path - - local result=$? - if [ $result -eq 2 ]; then - error_log "mongodb download fail" - exit - elif [ $result -eq 3 ]; then - error_log "mongodb extract fail" - exit - fi - + sync_third_party $base_url$target_url $target_path || exit } function sync_third_party() { diff --git a/bootstrap/common/util.sh b/bootstrap/common/util.sh index 4b8ee370..4ff790d4 100644 --- a/bootstrap/common/util.sh +++ b/bootstrap/common/util.sh @@ -33,6 +33,7 @@ function download() { local path=${2:-./} if [ -z "$url" ]; then + error_log "download fail - no url" return 1 fi @@ -44,7 +45,12 @@ function download() { { curl -LO $url > /dev/null 2>&1; cd - > /dev/null; } fi - return $? + if [ $? -ne 0 ]; then + error_log "download fail - invalid url or network disconnected" + return 2 + else + return 0 + fi } function has_container_directory() { @@ -61,10 +67,12 @@ function extract_archive() { local dest_path=${2:-./} if [ -z "$src_path" ]; then + error_log "extract fail - no path" return 1 fi if [ ! -f "$src_path" ]; then + error_log "extract fail - invalid path" return 2 fi @@ -77,10 +85,15 @@ function extract_archive() { case $src_path in *.tar.gz|*.tgz) tar -xvzf $src_path -C $dest_path > /dev/null 2>&1 ;; *.zip) unzip $src_path -d $dest_path > /dev/null 2>&1 ;; - *) return 3 ;; + *) error_log "extract fail - invalid file";return 3 ;; esac - return $? + if [ $? -ne 0 ]; then + error_log "extract fail - tar or unzip fail" + return 4 + else + return 0 + fi } # Print red color log. From 47a9422b546fe7148c6bb590b65079ebb37153aa Mon Sep 17 00:00:00 2001 From: cs-lee Date: Tue, 5 Dec 2017 08:27:03 -0800 Subject: [PATCH 5/5] Handle errors about third party download and extract Change already sync error number. ISSUE=none --- bootstrap/common/sync_third_party.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/common/sync_third_party.sh b/bootstrap/common/sync_third_party.sh index 7108239f..86bc5795 100644 --- a/bootstrap/common/sync_third_party.sh +++ b/bootstrap/common/sync_third_party.sh @@ -53,7 +53,7 @@ function sync_third_party() { local filename=$(basename $url) if ! needs_sync $url $target_path; then - return 1 + return 0 fi if is_windows_platform; then