Skip to content

Commit

Permalink
Handle errors about third party download and extract (#543)
Browse files Browse the repository at this point in the history
If script fail to download node binary, it should stop
and print right error log. This patch do it.
Additionally this patch add one function to print red color error log.

ISSUE=none
  • Loading branch information
cs-lee authored and romandev committed Dec 20, 2017
1 parent 9bb26d9 commit 94e8537
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
6 changes: 3 additions & 3 deletions bootstrap/common/sync_third_party.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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
Expand Down
23 changes: 21 additions & 2 deletions bootstrap/common/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function download() {
local path=${2:-./}

if [ -z "$url" ]; then
error_log "download fail - no url"
return 1
fi

Expand All @@ -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() {
Expand All @@ -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

Expand All @@ -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"
}

0 comments on commit 94e8537

Please sign in to comment.