Ignore local paths in $PATH in find_tool
Fixes the installer failing if `./bin` is at the begging of `$PATH` Ensures the installer does not pick a local path to the git executable Could happen if one has `export PATH='./bin:$PATH` in the shell rc file then it would set USABLE_GIT to be `./bin/git` which later fails when another cd was executed So `command -v git` migth spit out `./bin/git` The fix is using `find_tool` instead of `command -v` and `find_tool` ignores all paths that do not start with a leading slash Co-authored-by: Adrian Ho <the.gromgit@gmail.com>
This commit is contained in:
128
install.sh
128
install.sh
@@ -73,7 +73,7 @@ ohai() {
|
||||
}
|
||||
|
||||
warn() {
|
||||
printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")"
|
||||
printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" >&2
|
||||
}
|
||||
|
||||
# Check if script is run non-interactively (e.g. CI)
|
||||
@@ -383,7 +383,7 @@ test_git() {
|
||||
fi
|
||||
|
||||
local git_version_output
|
||||
git_version_output="$("$1" --version 2>/dev/null)"
|
||||
git_version_output="$("$1" --version 2>/dev/null | awk '{ print $1 " " $2 " " $3 }')"
|
||||
version_ge "$(major_minor "${git_version_output##* }")" "$(major_minor "${REQUIRED_GIT_VERSION}")"
|
||||
}
|
||||
|
||||
@@ -405,7 +405,10 @@ find_tool() {
|
||||
local executable
|
||||
while read -r executable
|
||||
do
|
||||
if "test_$1" "${executable}"
|
||||
if [[ "${executable}" != /* ]]
|
||||
then
|
||||
warn "Ignoring ${executable} (relative paths don't work)"
|
||||
elif "test_$1" "${executable}"
|
||||
then
|
||||
echo "${executable}"
|
||||
break
|
||||
@@ -447,65 +450,6 @@ fi
|
||||
cd "/usr" || exit 1
|
||||
|
||||
####################################################################### script
|
||||
USABLE_GIT="$(command -v git)"
|
||||
if [[ -z "${USABLE_GIT}" ]]
|
||||
then
|
||||
abort "$(
|
||||
cat <<EOABORT
|
||||
You must install Git before installing Homebrew. See:
|
||||
${tty_underline}https://docs.brew.sh/Installation${tty_reset}
|
||||
EOABORT
|
||||
)"
|
||||
elif [[ -n "${HOMEBREW_ON_LINUX-}" ]]
|
||||
then
|
||||
USABLE_GIT="$(find_tool git)"
|
||||
if [[ -z "${USABLE_GIT}" ]]
|
||||
then
|
||||
abort "$(
|
||||
cat <<EOABORT
|
||||
The version of Git that was found does not satisfy requirements for Homebrew.
|
||||
Please install Git ${REQUIRED_GIT_VERSION} or newer and add it to your PATH.
|
||||
EOABORT
|
||||
)"
|
||||
elif [[ "${USABLE_GIT}" != /usr/bin/git ]]
|
||||
then
|
||||
export HOMEBREW_GIT_PATH="${USABLE_GIT}"
|
||||
ohai "Found Git: ${HOMEBREW_GIT_PATH}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! command -v curl >/dev/null
|
||||
then
|
||||
abort "$(
|
||||
cat <<EOABORT
|
||||
You must install cURL before installing Homebrew. See:
|
||||
${tty_underline}https://docs.brew.sh/Installation${tty_reset}
|
||||
EOABORT
|
||||
)"
|
||||
elif [[ -n "${HOMEBREW_ON_LINUX-}" ]]
|
||||
then
|
||||
USABLE_CURL="$(find_tool curl)"
|
||||
if [[ -z "${USABLE_CURL}" ]]
|
||||
then
|
||||
abort "$(
|
||||
cat <<EOABORT
|
||||
The version of cURL that was found does not satisfy requirements for Homebrew.
|
||||
Please install cURL ${REQUIRED_CURL_VERSION} or newer and add it to your PATH.
|
||||
EOABORT
|
||||
)"
|
||||
elif [[ "${USABLE_CURL}" != /usr/bin/curl ]]
|
||||
then
|
||||
export HOMEBREW_CURL_PATH="${USABLE_CURL}"
|
||||
ohai "Found cURL: ${HOMEBREW_CURL_PATH}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set HOMEBREW_DEVELOPER on Linux systems where usable Git/cURL is not in /usr/bin
|
||||
if [[ -n "${HOMEBREW_ON_LINUX-}" && (-n "${HOMEBREW_CURL_PATH-}" || -n "${HOMEBREW_GIT_PATH-}") ]]
|
||||
then
|
||||
ohai "Setting HOMEBREW_DEVELOPER to use Git/cURL not in /usr/bin"
|
||||
export HOMEBREW_DEVELOPER=1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
ohai 'Checking for `sudo` access (which may request your password)...'
|
||||
@@ -883,6 +827,66 @@ EOABORT
|
||||
)"
|
||||
fi
|
||||
|
||||
USABLE_GIT="$(find_tool git)"
|
||||
if [[ -z "${USABLE_GIT}" ]]
|
||||
then
|
||||
abort "$(
|
||||
cat <<EOABORT
|
||||
You must install Git before installing Homebrew. See:
|
||||
${tty_underline}https://docs.brew.sh/Installation${tty_reset}
|
||||
EOABORT
|
||||
)"
|
||||
elif [[ -n "${HOMEBREW_ON_LINUX-}" ]]
|
||||
then
|
||||
USABLE_GIT="$(find_tool git)"
|
||||
if [[ -z "${USABLE_GIT}" ]]
|
||||
then
|
||||
abort "$(
|
||||
cat <<EOABORT
|
||||
The version of Git that was found does not satisfy requirements for Homebrew.
|
||||
Please install Git ${REQUIRED_GIT_VERSION} or newer and add it to your PATH.
|
||||
EOABORT
|
||||
)"
|
||||
elif [[ "${USABLE_GIT}" != /usr/bin/git ]]
|
||||
then
|
||||
export HOMEBREW_GIT_PATH="${USABLE_GIT}"
|
||||
ohai "Found Git: ${HOMEBREW_GIT_PATH}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! command -v curl >/dev/null
|
||||
then
|
||||
abort "$(
|
||||
cat <<EOABORT
|
||||
You must install cURL before installing Homebrew. See:
|
||||
${tty_underline}https://docs.brew.sh/Installation${tty_reset}
|
||||
EOABORT
|
||||
)"
|
||||
elif [[ -n "${HOMEBREW_ON_LINUX-}" ]]
|
||||
then
|
||||
USABLE_CURL="$(find_tool curl)"
|
||||
if [[ -z "${USABLE_CURL}" ]]
|
||||
then
|
||||
abort "$(
|
||||
cat <<EOABORT
|
||||
The version of cURL that was found does not satisfy requirements for Homebrew.
|
||||
Please install cURL ${REQUIRED_CURL_VERSION} or newer and add it to your PATH.
|
||||
EOABORT
|
||||
)"
|
||||
elif [[ "${USABLE_CURL}" != /usr/bin/curl ]]
|
||||
then
|
||||
export HOMEBREW_CURL_PATH="${USABLE_CURL}"
|
||||
ohai "Found cURL: ${HOMEBREW_CURL_PATH}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set HOMEBREW_DEVELOPER on Linux systems where usable Git/cURL is not in /usr/bin
|
||||
if [[ -n "${HOMEBREW_ON_LINUX-}" && (-n "${HOMEBREW_CURL_PATH-}" || -n "${HOMEBREW_GIT_PATH-}") ]]
|
||||
then
|
||||
ohai "Setting HOMEBREW_DEVELOPER to use Git/cURL not in /usr/bin"
|
||||
export HOMEBREW_DEVELOPER=1
|
||||
fi
|
||||
|
||||
ohai "Downloading and installing Homebrew..."
|
||||
(
|
||||
cd "${HOMEBREW_REPOSITORY}" >/dev/null || return
|
||||
|
||||
Reference in New Issue
Block a user