installer: reorganise and add comments

This commit is contained in:
Marc Cornellà 2016-05-30 18:05:29 +02:00
parent 73ef051aae
commit f94443925d

View File

@ -1,7 +1,18 @@
#!/bin/sh
#
# This script should be run via curl:
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# or wget:
# sh -c "$(wget -qO- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
#
# As an alternative, you can download the install script separately and
# run it afterwards with `sh install.sh'
#
set -e
# Test command existence (POSIX compatible)
# Default location
ZSH=${ZSH:-~/.oh-my-zsh}
command_exists() {
command -v "$@" >/dev/null 2>&1
}
@ -30,17 +41,15 @@ main() {
fi
if ! command_exists zsh; then
printf "${YELLOW}Zsh is not installed!${NORMAL} Please install zsh first!\n"
echo "${YELLOW}Zsh is not installed!${NORMAL} Please install zsh first!"
exit 1
fi
if [ ! -n "$ZSH" ]; then
ZSH=~/.oh-my-zsh
fi
if [ -d "$ZSH" ]; then
printf "${YELLOW}You already have Oh My Zsh installed.${NORMAL}\n"
printf "You'll need to remove $ZSH if you want to re-install.\n"
cat <<-EOF
${YELLOW}You already have Oh My Zsh installed.${NORMAL}
You'll need to remove $ZSH if you want to re-install.
EOF
exit 1
fi
@ -51,31 +60,34 @@ main() {
# precedence over umasks except for filesystems mounted with option "noacl".
umask g-w,o-w
printf "${BLUE}Cloning Oh My Zsh...${NORMAL}\n"
echo "${BLUE}Cloning Oh My Zsh...${NORMAL}"
command_exists git || {
echo "Error: git is not installed"
exit 1
}
# The Windows (MSYS) Git is not compatible with normal use on cygwin
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
if [ "$OSTYPE" = cygwin ] && git --version | grep -q msysgit; then
cat <<-EOF
Error: Windows/MSYS Git is not supported on Cygwin
Error: Make sure the Cygwin git package is installed and is first on the $PATH
EOF
exit 1
fi
env git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git "$ZSH" || {
printf "Error: git clone of oh-my-zsh repo failed\n"
git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git "$ZSH" || {
echo "Error: git clone of oh-my-zsh repo failed"
exit 1
}
printf "${BLUE}Looking for an existing zsh config...${NORMAL}\n"
echo "${BLUE}Looking for an existing zsh config...${NORMAL}"
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
printf "${YELLOW}Found ~/.zshrc.${NORMAL} ${GREEN}Backing up to ~/.zshrc.pre-oh-my-zsh${NORMAL}\n";
echo "${YELLOW}Found ~/.zshrc.${GREEN} Backing up to ~/.zshrc.pre-oh-my-zsh.${NORMAL}"
mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh;
fi
printf "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc${NORMAL}\n"
echo "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc.${NORMAL}"
cp "$ZSH/templates/zshrc.zsh-template" ~/.zshrc
sed "/^export ZSH=/ c\\
export ZSH=\"$ZSH\"
@ -87,31 +99,36 @@ export ZSH=\"$ZSH\"
if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
# If this platform provides a "chsh" command (not Cygwin), do it, man!
if command_exists chsh; then
printf "${BLUE}Time to change your default shell to zsh!${NORMAL}\n"
echo "${BLUE}Time to change your default shell to zsh!${NORMAL}"
chsh -s $(grep /zsh$ /etc/shells | tail -1)
# Else, suggest the user do so manually.
else
printf "I can't change your shell automatically because this system does not have chsh.\n"
printf "${BLUE}Please manually change your default shell to zsh!${NORMAL}\n"
cat <<-EOF
I can't change your shell automatically because this system does not have chsh.
${BLUE}Please manually change your default shell to zsh${NORMAL}
EOF
fi
fi
printf "${GREEN}"
echo ' __ __ '
echo ' ____ / /_ ____ ___ __ __ ____ _____/ /_ '
echo ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '
echo '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '
echo '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '
echo ' /____/ ....is now installed!'
echo ''
echo ''
echo 'Please look over the ~/.zshrc file to select plugins, themes, and options.'
echo ''
echo 'p.s. Follow us at https://twitter.com/ohmyzsh'
echo ''
echo 'p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh'
echo ''
printf "${NORMAL}"
printf "$GREEN"
cat <<-'EOF'
__ __
____ / /_ ____ ___ __ __ ____ _____/ /_
/ __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
/____/ ....is now installed!
Please look over the ~/.zshrc file to select plugins, themes, and options.
p.s. Follow us on https://twitter.com/ohmyzsh
p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh
EOF
printf "$NORMAL"
env zsh -l
}