From f568633bf060c18cc0866b4018842ce9ec9da33a Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Fri, 6 Aug 2021 21:34:01 +0100 Subject: [PATCH] FIX: Use the return code from which correctly The return code of which is the number of arguments which failed... but what we actually want is 0 when at least one of the docker exectutables is found and nonzero when none are found. --- discourse-setup | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/discourse-setup b/discourse-setup index 3548feb..df2d5be 100755 --- a/discourse-setup +++ b/discourse-setup @@ -122,14 +122,22 @@ check_IP_match() { ## ## Do we have docker? ## -check_and_install_docker () { - if ! which docker.io docker 2>/dev/null ; then - echo Failed to find docker.io or docker on your PATH. + +check_docker() { + (which docker || which docker.io) 2>/dev/null + echo $? +} + +check_and_install_docker() { + found_docker=$(check_docker) + if [ "$found_docker" -ne 0 ]; then + echo Failed to find docker or docker.io on your PATH. read -p "Enter to install Docker from https://get.docker.com/ or Ctrl+C to exit" curl https://get.docker.com/ | sh - if ! which docker.io docker 2>/dev/null ; then - echo Still failed to find docker.io or docker on your PATH. + found_docker=$(check_docker) + if [ "$found_docker" -ne 0 ]; then + echo Still failed to find docker or docker.io on your PATH. echo Docker install failed. Quitting. exit fi -- 2.25.1