Browse Source

chg: [install.sh] improve error detection and signaling

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
pull/1/head
Valentin Lab 5 years ago
parent
commit
a3bf2236ec
  1. 39
      src/install.sh

39
src/install.sh

@ -152,16 +152,23 @@ install_file() {
get_charm_store() { get_charm_store() {
local branch="${1:master}" local branch="${1:master}"
if ! [ -d "$CHARM_PATH" ]; then 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 else
echo "Updating existing charm-store in '$CHARM_PATH'."
info "Updating existing charm-store in '$CHARM_PATH'."
cd "$CHARM_PATH" || exit 1 cd "$CHARM_PATH" || exit 1
git fetch && git fetch &&
git checkout "$branch" && git checkout "$branch" &&
git pull -r || { git pull -r || {
warn "Could not update charm-store, do you have devs ingoing ?" 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 fi
} }
@ -173,12 +180,20 @@ fetch_binary() {
( (
tmpfile=$(mktemp) && trap "rm -f '$tmpfile'" EXIT && tmpfile=$(mktemp) && trap "rm -f '$tmpfile'" EXIT &&
curl -sS "$url" > "$tmpfile" && 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")" == "<!DOCTYPE html>"* ]]; 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 else
mv "$tmpfile" "$BIN_PATH/$name"
echo " .. Done !"
mv "$tmpfile" "$BIN_PATH/$name" &&
echo " .. ${GREEN}Done${NORMAL}." >&2
fi fi
) || return 1 ) || return 1
hash -r hash -r
@ -212,17 +227,17 @@ install.linux() {
COMPOSE_OPTION_FILE=/etc/compose/local.conf COMPOSE_OPTION_FILE=/etc/compose/local.conf
fi 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 if [[ ":$PATH:" != *":$BIN_PATH:"* ]]; then
warn "Please ensure that '$BIN_PATH' is in your \$PATH to ensure" \ warn "Please ensure that '$BIN_PATH' is in your \$PATH to ensure" \
"the simple usage of 'compose' command." "the simple usage of 'compose' command."
fi fi
get_charm_store "${DEPLOY_REF}" || exit 1
get_charm_store "${DEPLOY_REF}" || return 1
cat <<EOF | install_file "$COMPOSE_OPTION_FILE"
cat <<EOF | install_file "$COMPOSE_OPTION_FILE" || return 1
#CHARM_STORE=$CHARM_STORE #CHARM_STORE=$CHARM_STORE
COMPOSE_DOCKER_IMAGE=docker.0k.io/compose:${DEPLOY_REF//\//-} COMPOSE_DOCKER_IMAGE=docker.0k.io/compose:${DEPLOY_REF//\//-}

Loading…
Cancel
Save