From b9b2c58c48cbc2c09d96c2025c75ef9ffee2f628 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 20 Apr 2021 11:33:32 +0900 Subject: [PATCH] tools/install: Fix Bash version check --- tools/install.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index efe81f5..ea6abee 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -1,11 +1,22 @@ #!/usr/bin/env bash +# Checks the minium version of bash (v4) installed, +# stops the installation if check fails +if [ -z "$BASH_VERSION" ] || \ + { bash_major_version=$(echo "$BASH_VERSION" | cut -d '.' -f 1); + [ "${bash_major_version}" -lt "4" ]; }; then + printf "Error: Bash 4 required for Oh My Bash.\n" + printf "Error: Upgrade Bash and try again.\n" + exit 1 +fi + main() { # Use colors, but only if connected to a terminal, and that terminal # supports them. if hash tput >/dev/null 2>&1; then ncolors=$(tput colors 2>/dev/null || tput Co 2>/dev/null || echo -1) fi + if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then RED=$(tput setaf 1 2>/dev/null || tput AF 1 2>/dev/null) GREEN=$(tput setaf 2 2>/dev/null || tput AF 2 2>/dev/null) @@ -26,17 +37,6 @@ main() { # which may fail on systems lacking tput or terminfo set -e - # Checks the minium version of bash (v4) installed, - # stops the installation if check fails - if [ -n $BASH_VERSION ]; then - bash_major_version=$(echo $BASH_VERSION | cut -d '.' -f 1) - if [ "${bash_major_version}" -lt "4" ]; then - printf "Error: Bash 4 required for Oh My Bash.\n" - printf "Error: Upgrade Bash and try again.\n" - exit 1 - fi - fi - if [ ! -n "$OSH" ]; then OSH=$HOME/.oh-my-bash fi