From a3bf2236ec836e8d9f2f4d72f6a778ad4c8c2526 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 17 Dec 2019 16:39:15 +0100 Subject: [PATCH] chg: [install.sh] improve error detection and signaling Signed-off-by: Valentin Lab --- src/install.sh | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) mode change 100644 => 100755 src/install.sh diff --git a/src/install.sh b/src/install.sh old mode 100644 new mode 100755 index 309d146..b4b0e1f --- a/src/install.sh +++ b/src/install.sh @@ -152,16 +152,23 @@ install_file() { get_charm_store() { local branch="${1:master}" if ! [ -d "$CHARM_PATH" ]; then - echo "Creating charm-store in '$CHARM_PATH'." - git clone https://git.0k.io/0k-charms.git -b "$branch" "$CHARM_PATH" || exit 1 + info "Creating charm-store in '$CHARM_PATH'.." + git clone https://git.0k.io/0k-charms.git -b "$branch" "$CHARM_PATH" || { + echo " .. ${RED}Failed${NORMAL}." >&2 + return 1 + } + echo " .. ${GREEN}Done${NORMAL}." >&2 else - echo "Updating existing charm-store in '$CHARM_PATH'." + info "Updating existing charm-store in '$CHARM_PATH'." cd "$CHARM_PATH" || exit 1 git fetch && git checkout "$branch" && git pull -r || { warn "Could not update charm-store, do you have devs ingoing ?" + echo " .. ${BLUE}No action${NORMAL}." >&2 + return 0 } + echo " .. ${GREEN}Done${NORMAL}." >&2 fi } @@ -173,12 +180,20 @@ fetch_binary() { ( tmpfile=$(mktemp) && trap "rm -f '$tmpfile'" EXIT && curl -sS "$url" > "$tmpfile" && - chmod +x "$tmpfile" - if [ -e "$BIN_PATH/$name" ] && diff "$tmpfile" "$BIN_PATH/$name"; then - echo " .. Done (File '$BIN_PATH/$name' was already up to date.)" + chmod +x "$tmpfile" || { + echo " .. ${RED}Failed${NORMAL}." >&2 + return 1 + } + if [[ "$(cat "$tmpfile")" == ""* ]]; then + echo " $GRAY|$NORMAL fetching: $url" >&2 + echo " .. ${RED}Failed${NORMAL} (fetched content is HTML !?!)." >&2 + return 1 + fi + if [ -e "$BIN_PATH/$name" ] && diff "$tmpfile" "$BIN_PATH/$name" >/dev/null; then + echo " .. ${GREEN}Done${NORMAL} (File '$BIN_PATH/$name' was already up to date.)" >&2 else - mv "$tmpfile" "$BIN_PATH/$name" - echo " .. Done !" + mv "$tmpfile" "$BIN_PATH/$name" && + echo " .. ${GREEN}Done${NORMAL}." >&2 fi ) || return 1 hash -r @@ -212,17 +227,17 @@ install.linux() { COMPOSE_OPTION_FILE=/etc/compose/local.conf fi - fetch_binary https://git.0k.io/0k-compose.git/plain/bin/compose?h="${DEPLOY_REF}" compose - get_docker_ip + fetch_binary "https://git.0k.io/0k-compose.git/plain/bin/compose?h=${DEPLOY_REF}" compose || return 1 + get_docker_ip || return 1 if [[ ":$PATH:" != *":$BIN_PATH:"* ]]; then warn "Please ensure that '$BIN_PATH' is in your \$PATH to ensure" \ "the simple usage of 'compose' command." fi - get_charm_store "${DEPLOY_REF}" || exit 1 + get_charm_store "${DEPLOY_REF}" || return 1 - cat <