oh-my-bash/tools/install.sh

107 lines
3.8 KiB
Bash
Raw Normal View History

2017-03-19 08:40:25 +00:00
#!/usr/bin/env bash
# Checks the minium version of bash (v3.2) installed,
2021-04-20 02:33:32 +00:00
# stops the installation if check fails
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"
2021-04-20 02:33:32 +00:00
printf "Error: Upgrade Bash and try again.\n"
exit 1
fi
2017-03-19 08:40:25 +00:00
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)
2017-03-19 08:40:25 +00:00
fi
2021-04-20 02:33:32 +00:00
2021-04-20 02:56:41 +00:00
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)
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)
2017-03-19 08:40:25 +00:00
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
fi
# Only enable exit-on-error after the non-critical colorization stuff,
# which may fail on systems lacking tput or terminfo
set -e
2021-04-20 02:56:41 +00:00
if [[ ! $OSH ]]; then
OSH=~/.oh-my-bash
2017-03-19 08:40:25 +00:00
fi
2021-04-20 02:56:41 +00:00
if [[ -d $OSH ]]; then
2017-03-19 08:40:25 +00:00
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
fi
# Prevent the cloned repository from having insecure permissions. Failing to do
# so causes compinit() calls to fail with "command not found: compdef" errors
# for users with insecure umasks (e.g., "002", allowing group writability). Note
# that this will be ignored under Cygwin by default, as Windows ACLs take
# precedence over umasks except for filesystems mounted with option "noacl".
umask g-w,o-w
printf "${BLUE}Cloning Oh My Bash...${NORMAL}\n"
hash git >/dev/null 2>&1 || {
echo "Error: git is not installed"
exit 1
}
# The Windows (MSYS) Git is not compatible with normal use on cygwin
2021-04-20 02:56:41 +00:00
if [[ $OSTYPE = cygwin ]]; then
2017-03-19 08:40:25 +00:00
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"
exit 1
fi
fi
env git clone --depth=1 https://github.com/ohmybash/oh-my-bash.git "$OSH" || {
2017-03-19 08:40:25 +00:00
printf "Error: git clone of oh-my-bash repo failed\n"
exit 1
}
printf "${BLUE}Looking for an existing bash config...${NORMAL}\n"
2021-04-20 02:56:41 +00:00
if [[ -f ~/.bashrc || -h ~/.bashrc ]]; then
2017-11-08 04:52:57 +00:00
printf "${YELLOW}Found ~/.bashrc.${NORMAL} ${GREEN}Backing up to ~/.bashrc.pre-oh-my-bash${NORMAL}\n";
mv ~/.bashrc ~/.bashrc.pre-oh-my-bash;
2017-03-19 08:40:25 +00:00
fi
printf "${BLUE}Using the Oh My Bash template file and adding it to ~/.bashrc${NORMAL}\n"
cp "$OSH"/templates/bashrc.osh-template ~/.bashrc
2017-03-19 08:40:25 +00:00
sed "/^export OSH=/ c\\
export OSH=$OSH
" ~/.bashrc > ~/.bashrc-ombtemp
mv -f ~/.bashrc-ombtemp ~/.bashrc
2017-03-19 08:40:25 +00:00
# MOTD message :)
printf '%s' "$GREEN"
printf '%s\n' \
' __ __ __ ' \
' ____ / /_ ____ ___ __ __ / /_ ____ ______/ /_ ' \
' / __ \/ __ \ / __ `__ \/ / / / / __ \/ __ `/ ___/ __ \' \
'/ /_/ / / / / / / / / / / /_/ / / /_/ / /_/ (__ ) / / /' \
'\____/_/ /_/ /_/ /_/ /_/\__, / /_.___/\__,_/____/_/ /_/ ' \
' /____/ .... is now installed!' \
"Please look over the ~/.bashrc file to select plugins, themes, and options"
2017-10-10 11:13:21 +00:00
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 ~/.bashrc
2017-03-19 08:40:25 +00:00
}
main