mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-05-11 05:55:37 +00:00
Merge pull request #214 from akinomyoga/fix-install-script
Fix install script for #213
This commit is contained in:
+35
-31
@@ -1,18 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Checks the minium version of bash (v3.2) installed,
|
||||
# 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"
|
||||
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 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)"
|
||||
|
||||
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)
|
||||
else
|
||||
RED=""
|
||||
GREEN=""
|
||||
@@ -26,22 +41,11 @@ 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
|
||||
if [[ ! $OSH ]]; then
|
||||
OSH=~/.oh-my-bash
|
||||
fi
|
||||
|
||||
if [ ! -n "$OSH" ]; then
|
||||
OSH=$HOME/.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,30 +64,30 @@ 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"
|
||||
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 +99,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
|
||||
}
|
||||
|
||||
|
||||
|
||||
+7
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user