From 39c9598081d7941df3ead2377ae06a5affcc1045 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 20 Apr 2021 11:43:23 +0900 Subject: [PATCH 1/5] tools/install: Add support termcap-based tput --- tools/install.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index a5e963b..efe81f5 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -3,16 +3,16 @@ main() { # Use colors, but only if connected to a terminal, and that terminal # supports them. - if which tput >/dev/null 2>&1; then - ncolors=$(tput colors) + 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)" - GREEN="$(tput setaf 2)" - YELLOW="$(tput setaf 3)" - BLUE="$(tput setaf 4)" - BOLD="$(tput bold)" - NORMAL="$(tput sgr0)" + 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) + YELLOW=$(tput setaf 3 2>/dev/null || tput AF 3 2>/dev/null) + BLUE=$(tput setaf 4 2>/dev/null || tput AF 4 2>/dev/null) + BOLD=$(tput bold 2>/dev/null || tput md 2>/dev/null) + NORMAL=$(tput sgr0 2>/dev/null || tput me 2>/dev/null) else RED="" GREEN="" From b9b2c58c48cbc2c09d96c2025c75ef9ffee2f628 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 20 Apr 2021 11:33:32 +0900 Subject: [PATCH 2/5] 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 From c22b97e09a07efeb971907d12ee78d0689184825 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 20 Apr 2021 11:46:32 +0900 Subject: [PATCH 3/5] tools/{,un}install: Quote arguments properly --- tools/install.sh | 16 ++++++++-------- tools/uninstall.sh | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index ea6abee..e436a58 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -38,7 +38,7 @@ main() { set -e if [ ! -n "$OSH" ]; then - OSH=$HOME/.oh-my-bash + OSH=~/.oh-my-bash fi if [ -d "$OSH" ]; then @@ -67,23 +67,23 @@ main() { exit 1 fi fi - env git clone --depth=1 https://github.com/ohmybash/oh-my-bash.git $OSH || { + env git clone --depth=1 https://github.com/ohmybash/oh-my-bash.git "$OSH" || { printf "Error: git clone of oh-my-bash repo failed\n" exit 1 } printf "${BLUE}Looking for an existing bash config...${NORMAL}\n" - if [ -f $HOME/.bashrc ] || [ -h $HOME/.bashrc ]; then + if [ -f ~/.bashrc ] || [ -h ~/.bashrc ]; then printf "${YELLOW}Found ~/.bashrc.${NORMAL} ${GREEN}Backing up to ~/.bashrc.pre-oh-my-bash${NORMAL}\n"; - mv $HOME/.bashrc $HOME/.bashrc.pre-oh-my-bash; + mv ~/.bashrc ~/.bashrc.pre-oh-my-bash; fi printf "${BLUE}Using the Oh My Bash template file and adding it to ~/.bashrc${NORMAL}\n" - cp $OSH/templates/bashrc.osh-template $HOME/.bashrc + cp "$OSH"/templates/bashrc.osh-template ~/.bashrc sed "/^export OSH=/ c\\ export OSH=$OSH - " $HOME/.bashrc > $HOME/.bashrc-ombtemp - mv -f $HOME/.bashrc-ombtemp $HOME/.bashrc + " ~/.bashrc > ~/.bashrc-ombtemp + mv -f ~/.bashrc-ombtemp ~/.bashrc # MOTD message :) printf '%s' "$GREEN" @@ -95,7 +95,7 @@ export OSH=$OSH printf '%s\n' ' /____/ .... is now installed!' printf "%s\n" "Please look over the ~/.bashrc file to select plugins, themes, and options" printf "${BLUE}${BOLD}%s${NORMAL}\n" "To keep up on the latest news and updates, follow us on GitHub: https://github.com/ohmybash/oh-my-bash" - exec bash; source $HOME/.bashrc + exec bash; source ~/.bashrc } diff --git a/tools/uninstall.sh b/tools/uninstall.sh index 6e4fdde..0625573 100755 --- a/tools/uninstall.sh +++ b/tools/uninstall.sh @@ -7,22 +7,22 @@ if [ "$confirmation" != y ] && [ "$confirmation" != Y ]; then fi echo "Removing ~/.oh-my-bash" -if [ -d $HOME/.oh-my-bash ]; then - rm -rf $HOME/.oh-my-bash +if [ -d ~/.oh-my-bash ]; then + rm -rf ~/.oh-my-bash fi echo "Looking for original bash config..." -if [ -f $HOME/.bashrc.pre-oh-my-bash ] || [ -h $HOME/.bashrc.pre-oh-my-bash ]; then +if [ -f ~/.bashrc.pre-oh-my-bash ] || [ -h ~/.bashrc.pre-oh-my-bash ]; then echo "Found ~/.bashrc.pre-oh-my-bash -- Restoring to ~/.bashrc"; - if [ -f $HOME/.bashrc ] || [ -h $HOME/.bashrc ]; then + if [ -f ~/.bashrc ] || [ -h ~/.bashrc ]; then bashrc_SAVE=".bashrc.omb-uninstalled-$(date +%Y%m%d%H%M%S)"; echo "Found ~/.bashrc -- Renaming to ~/${bashrc_SAVE}"; - mv $HOME/.bashrc $HOME/"${bashrc_SAVE}"; + mv ~/.bashrc ~/"${bashrc_SAVE}"; fi - mv $HOME/.bashrc.pre-oh-my-bash $HOME/.bashrc; - exec bash; source $HOME/.bashrc + mv ~/.bashrc.pre-oh-my-bash ~/.bashrc; + exec bash; source ~/.bashrc echo "Your original bash config was restored. Please restart your session." else From 703e2864d4595a7e4634d458a0c2f1dcf5bd682e Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 20 Apr 2021 11:56:41 +0900 Subject: [PATCH 4/5] tools/install: Use condtional command --- tools/install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index e436a58..7386013 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -17,7 +17,7 @@ main() { ncolors=$(tput colors 2>/dev/null || tput Co 2>/dev/null || echo -1) fi - if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then + 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) YELLOW=$(tput setaf 3 2>/dev/null || tput AF 3 2>/dev/null) @@ -37,11 +37,11 @@ main() { # which may fail on systems lacking tput or terminfo set -e - if [ ! -n "$OSH" ]; then + if [[ ! $OSH ]]; then OSH=~/.oh-my-bash fi - if [ -d "$OSH" ]; then + if [[ -d $OSH ]]; then printf "${YELLOW}You already have Oh My Bash installed.${NORMAL}\n" printf "You'll need to remove $OSH if you want to re-install.\n" exit @@ -60,7 +60,7 @@ main() { exit 1 } # The Windows (MSYS) Git is not compatible with normal use on cygwin - if [ "$OSTYPE" = cygwin ]; then + if [[ $OSTYPE = cygwin ]]; then if git --version | grep msysgit > /dev/null; then echo "Error: Windows/MSYS Git is not supported on Cygwin" echo "Error: Make sure the Cygwin git package is installed and is first on the path" @@ -73,7 +73,7 @@ main() { } printf "${BLUE}Looking for an existing bash config...${NORMAL}\n" - if [ -f ~/.bashrc ] || [ -h ~/.bashrc ]; then + if [[ -f ~/.bashrc || -h ~/.bashrc ]]; then printf "${YELLOW}Found ~/.bashrc.${NORMAL} ${GREEN}Backing up to ~/.bashrc.pre-oh-my-bash${NORMAL}\n"; mv ~/.bashrc ~/.bashrc.pre-oh-my-bash; fi From 5421f3a3429d4335dc6a3ca94b70e8b7443cf6cf Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Wed, 29 Dec 2021 09:01:57 +0900 Subject: [PATCH 5/5] tools/install: Update the Bash-version check --- tools/install.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index 7386013..e68f3bf 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -1,11 +1,15 @@ #!/usr/bin/env bash -# Checks the minium version of bash (v4) installed, +# Checks the minium version of bash (v3.2) 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" +if [ -z "${BASH_VERSION-}" ]; then + printf "Error: Bash 3.2 required for Oh My Bash.\n" + printf "Error: Install Bash and try running this script with Bash.\n" + exit 1 +fi + +if [[ ! ${BASH_VERSINFO[0]-} ]] || ((BASH_VERSINFO[0] < 3 || BASH_VERSINFO[0] == 3 && BASH_VERSINFO[1] < 2)); then + printf "Error: Bash 3.2 required for Oh My Bash.\n" printf "Error: Upgrade Bash and try again.\n" exit 1 fi