installer: use tabs to allow future heredocs

This will allow us to use tab stripping heredocs with `<<-'.
See http://www.tldp.org/LDP/abs/html/here-docs.html#EX71A

Add editorconfig file to enforce this style.
See http://editorconfig.org for more information.
This commit is contained in:
Marc Cornellà 2016-08-09 02:28:47 +02:00
parent 2eb16ea8e3
commit ad1a26a7d4
2 changed files with 109 additions and 100 deletions

10
.editorconfig Normal file
View File

@ -0,0 +1,10 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
[*.sh]
indent_size = 4
indent_style = tab

View File

@ -3,123 +3,122 @@ set -e
# Test command existence (POSIX compatible) # Test command existence (POSIX compatible)
command_exists() { command_exists() {
command -v "$@" >/dev/null 2>&1 command -v "$@" >/dev/null 2>&1
} }
# Set up color sequences # Set up color sequences
setup_color() { setup_color() {
if command_exists tput; then if command_exists tput; then
ncolors=$(tput colors) ncolors=$(tput colors)
else else
ncolors=0 ncolors=0
fi fi
# Only use colors if connected to a terminal that supports them # Only use colors if connected to a terminal that supports them
if [ -t 1 ] && [ $ncolors -ge 8 ]; then if [ -t 1 ] && [ $ncolors -ge 8 ]; then
RED="$(tput setaf 1)" RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)" GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)" YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)" BLUE="$(tput setaf 4)"
BOLD="$(tput bold)" BOLD="$(tput bold)"
NORMAL="$(tput sgr0)" NORMAL="$(tput sgr0)"
else else
RED="" RED=""
GREEN="" GREEN=""
YELLOW="" YELLOW=""
BLUE="" BLUE=""
BOLD="" BOLD=""
NORMAL="" NORMAL=""
fi fi
} }
main() { main() {
setup_color setup_color
if ! command_exists zsh; then if ! command_exists zsh; then
printf "${YELLOW}Zsh is not installed!${NORMAL} Please install zsh first!\n" printf "${YELLOW}Zsh is not installed!${NORMAL} Please install zsh first!\n"
exit 1 exit 1
fi fi
if [ ! -n "$ZSH" ]; then if [ ! -n "$ZSH" ]; then
ZSH=~/.oh-my-zsh ZSH=~/.oh-my-zsh
fi fi
if [ -d "$ZSH" ]; then if [ -d "$ZSH" ]; then
printf "${YELLOW}You already have Oh My Zsh installed.${NORMAL}\n" 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" printf "You'll need to remove $ZSH if you want to re-install.\n"
exit 1 exit 1
fi fi
# Prevent the cloned repository from having insecure permissions. Failing to do # Prevent the cloned repository from having insecure permissions. Failing to do
# so causes compinit() calls to fail with "command not found: compdef" errors # so causes compinit() calls to fail with "command not found: compdef" errors
# for users with insecure umasks (e.g., "002", allowing group writability). Note # 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 # that this will be ignored under Cygwin by default, as Windows ACLs take
# precedence over umasks except for filesystems mounted with option "noacl". # precedence over umasks except for filesystems mounted with option "noacl".
umask g-w,o-w umask g-w,o-w
printf "${BLUE}Cloning Oh My Zsh...${NORMAL}\n" printf "${BLUE}Cloning Oh My Zsh...${NORMAL}\n"
command_exists git || { command_exists git || {
echo "Error: git is not installed" echo "Error: git is not installed"
exit 1 exit 1
} }
# The Windows (MSYS) Git is not compatible with normal use on cygwin # 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 if git --version | grep msysgit > /dev/null; then
echo "Error: Windows/MSYS Git is not supported on Cygwin" 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" echo "Error: Make sure the Cygwin git package is installed and is first on the path"
exit 1 exit 1
fi fi
fi fi
env git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git $ZSH || { 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" printf "Error: git clone of oh-my-zsh repo failed\n"
exit 1 exit 1
} }
printf "${BLUE}Looking for an existing zsh config...${NORMAL}\n"
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
printf "${YELLOW}Found ~/.zshrc.${NORMAL} ${GREEN}Backing up to ~/.zshrc.pre-oh-my-zsh${NORMAL}\n";
mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh;
fi
printf "${BLUE}Looking for an existing zsh config...${NORMAL}\n" printf "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc${NORMAL}\n"
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then cp $ZSH/templates/zshrc.zsh-template ~/.zshrc
printf "${YELLOW}Found ~/.zshrc.${NORMAL} ${GREEN}Backing up to ~/.zshrc.pre-oh-my-zsh${NORMAL}\n"; sed "/^export ZSH=/ c\\
mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh; export ZSH=$ZSH
fi " ~/.zshrc > ~/.zshrc-omztemp
mv -f ~/.zshrc-omztemp ~/.zshrc
printf "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc${NORMAL}\n" # If this user's login shell is not already "zsh", attempt to switch.
cp $ZSH/templates/zshrc.zsh-template ~/.zshrc TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)')
sed "/^export ZSH=/ c\\ if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
export ZSH=$ZSH # If this platform provides a "chsh" command (not Cygwin), do it, man!
" ~/.zshrc > ~/.zshrc-omztemp if command_exists chsh; then
mv -f ~/.zshrc-omztemp ~/.zshrc printf "${BLUE}Time to change your default shell to zsh!${NORMAL}\n"
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"
fi
fi
# If this user's login shell is not already "zsh", attempt to switch. printf "${GREEN}"
TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)') echo ' __ __ '
if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then echo ' ____ / /_ ____ ___ __ __ ____ _____/ /_ '
# If this platform provides a "chsh" command (not Cygwin), do it, man! echo ' / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ '
if command_exists chsh; then echo '/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / '
printf "${BLUE}Time to change your default shell to zsh!${NORMAL}\n" echo '\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '
chsh -s $(grep /zsh$ /etc/shells | tail -1) echo ' /____/ ....is now installed!'
# Else, suggest the user do so manually. echo ''
else echo ''
printf "I can't change your shell automatically because this system does not have chsh.\n" echo 'Please look over the ~/.zshrc file to select plugins, themes, and options.'
printf "${BLUE}Please manually change your default shell to zsh!${NORMAL}\n" echo ''
fi echo 'p.s. Follow us at https://twitter.com/ohmyzsh.'
fi echo ''
echo 'p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.'
printf "${GREEN}" echo ''
echo ' __ __ ' printf "${NORMAL}"
echo ' ____ / /_ ____ ___ __ __ ____ _____/ /_ ' env zsh
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 and t-shirts at https://shop.planetargon.com.'
echo ''
printf "${NORMAL}"
env zsh
} }
main main