diff --git a/bootstrap/common/sync_third_party.sh b/bootstrap/common/sync_third_party.sh index 95093cca..86bc5795 100644 --- a/bootstrap/common/sync_third_party.sh +++ b/bootstrap/common/sync_third_party.sh @@ -29,7 +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 + sync_third_party $base_url$target_url $target_path || exit } function sync_mongodb() { @@ -44,7 +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 + sync_third_party $base_url$target_url $target_path || exit } function sync_third_party() { @@ -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 diff --git a/bootstrap/common/util.sh b/bootstrap/common/util.sh index c3a0a91e..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,7 +85,18 @@ 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 ;; + *) 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. +function error_log() { + echo -e "\e[31m$1\e[39m" }