From 90cf26ba437c7ba707d7d3a6c37b88e6b81dc664 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Fri, 13 Dec 2019 18:35:50 +0100 Subject: [PATCH] chg: dev: [install.sh] refactor out the fetching of binary !minor Signed-off-by: Valentin Lab --- src/install.sh | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/install.sh b/src/install.sh index b372b4b..1019339 100644 --- a/src/install.sh +++ b/src/install.sh @@ -215,6 +215,32 @@ get_charm_store() { } +fetch_binary() { + local url="$1" name="$2" bin_path tmpfile + mkdir -p "$BIN_PATH" || return 1 + info "Downloading '$name'..." + ( + 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.)" + else + mv "$tmpfile" "$BIN_PATH/$name" + echo " .. Done !" + fi + ) || return 1 + hash -r + if bin_path=$(type -p "$name"); then + if [ "$bin_path" != "$BIN_PATH/$name" ]; then + warn "Found a '$name' in \$PATH at '$bin_path'." \ + $'\n'" That doesn't match expected location '$BIN_PATH/$name'." \ + $'\n'" You might need to change you \$PATH to include '$BIN_PATH' before '${bin_path%/*}'." + fi + fi +} + + install.linux() { depends docker curl git @@ -230,29 +256,7 @@ install.linux() { COMPOSE_OPTION_FILE=/etc/compose/local.conf fi - ## COMPOSE - if compose=$(type -p "compose"); then - if [ "$compose" != "$BIN_PATH/compose" ]; then - warn "Found a 'compose' in \$PATH at '$compose' that doesn't match expected compose location '$BIN_PATH/compose'." \ - "Not doing anything." - elif [ -L "$compose" ]; then - warn "Found a 'compose' at '$compose' that is a link. " \ - "Not doing anything." - else - compose="" ## force overwrite - fi - fi - if [ -z "$compose" ]; then - mkdir -p "$BIN_PATH" || exit 1 - info "Downloading 'compose'..." - ( - set +x - curl -sS https://git.0k.io/0k-compose.git/plain/bin/compose > /tmp/compose - chmod -v +x /tmp/compose - mv -v /tmp/compose "$BIN_PATH/" - ) || exit 1 - echo " .. Done !" - fi + fetch_binary https://git.0k.io/0k-compose.git/plain/bin/compose compose if [[ ":$PATH:" != *":$BIN_PATH:"* ]]; then warn "Please ensure that '$BIN_PATH' is in your \$PATH to ensure" \