From 0b66d2850a1521fd40058f5cc9449c2f84ee0bb1 Mon Sep 17 00:00:00 2001 From: neo Date: Sat, 20 May 2023 10:49:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install-origin.sh | 136 +++++++++++++++++++++++++--------------------- install.sh | 136 +++++++++++++++++++++++++--------------------- 2 files changed, 148 insertions(+), 124 deletions(-) diff --git a/install-origin.sh b/install-origin.sh index ca4f7ba..687c979 100755 --- a/install-origin.sh +++ b/install-origin.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) @@ -304,6 +304,7 @@ check_run_command_as_root() { # Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there) [[ -f /.dockerenv ]] && return + [[ -f /run/.containerenv ]] && return [[ -f /proc/1/cgroup ]] && grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroup && return abort "Don't run this as root!" @@ -384,7 +385,12 @@ test_git() { local git_version_output git_version_output="$("$1" --version 2>/dev/null)" - version_ge "$(major_minor "${git_version_output##* }")" "$(major_minor "${REQUIRED_GIT_VERSION}")" + if [[ "${git_version_output}" =~ "git version "([^ ]*).* ]] + then + version_ge "$(major_minor "${BASH_REMATCH[1]}")" "$(major_minor "${REQUIRED_GIT_VERSION}")" + else + abort "Unexpected Git version: '${git_version_output}'!" + fi } # Search for the given executable in PATH (avoids a dependency on the `which` command) @@ -405,7 +411,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 +456,6 @@ fi cd "/usr" || exit 1 ####################################################################### script -USABLE_GIT="$(command -v git)" -if [[ -z "${USABLE_GIT}" ]] -then - abort "$( - cat </dev/null -then - abort "$( - cat </dev/null +then + abort "$( + cat </dev/null || return diff --git a/install.sh b/install.sh index f2edfe8..b5a24b6 100755 --- a/install.sh +++ b/install.sh @@ -74,7 +74,7 @@ ohai() { } warn() { - printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" + printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" >&2 } checkExecute() { @@ -336,6 +336,7 @@ check_run_command_as_root() { # Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there) [[ -f /.dockerenv ]] && return + [[ -f /run/.containerenv ]] && return [[ -f /proc/1/cgroup ]] && grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroup && return abort "Don't run this as root!" @@ -416,7 +417,12 @@ test_git() { local git_version_output git_version_output="$("$1" --version 2>/dev/null)" - version_ge "$(major_minor "${git_version_output##* }")" "$(major_minor "${REQUIRED_GIT_VERSION}")" + if [[ "${git_version_output}" =~ "git version "([^ ]*).* ]] + then + version_ge "$(major_minor "${BASH_REMATCH[1]}")" "$(major_minor "${REQUIRED_GIT_VERSION}")" + else + abort "Unexpected Git version: '${git_version_output}'!" + fi } # Search for the given executable in PATH (avoids a dependency on the `which` command) @@ -437,7 +443,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 @@ -479,65 +488,6 @@ fi cd "/usr" || exit 1 ####################################################################### script -USABLE_GIT="$(command -v git)" -if [[ -z "${USABLE_GIT}" ]] -then - abort "$( - cat </dev/null -then - abort "$( - cat </dev/null +then + abort "$( + cat </dev/null || return