zsh via package managers / return instead of exit
Installer tries to install zsh if no zsh is detected or if zsh is below 5.2. Currently tries for: * Brew (Mac) * apt-get (Debian/Ubuntu) * dnf (Fedora) * Pacman (Arch) Together these should cover about 99% of Zim users. Also use `return` instead of `exit`, which is a lot nicer to the invoking shell :)
This commit is contained in:
parent
0fe013e61b
commit
b3db9f6719
1 changed files with 38 additions and 18 deletions
|
@ -24,22 +24,44 @@ main() {
|
||||||
# which may fail on systems lacking tput or terminfo
|
# which may fail on systems lacking tput or terminfo
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Check if zsh exists
|
# Yes or no function
|
||||||
if [ ! "$(grep "/zsh$" "/etc/shells" | wc -l)" = 1 ]; then
|
yesno() {
|
||||||
# try installing from Homebrew
|
printf "${*} "
|
||||||
if [ ! "$(which -s brew)" = 0 ]; then
|
read answer
|
||||||
brew install zsh >/dev/null 2>&1
|
if printf "${answer}\n" | grep -iq "^y"; then
|
||||||
printf "${yellow}Installing zsh via Homebrew.. ${normal}\n"
|
return 0
|
||||||
else
|
else
|
||||||
printf "${red}Error: zsh isn't available! ${blue}Please install zsh first!${normal}\n"
|
return 1
|
||||||
exit 1
|
fi;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if `zsh` exists, or if `zsh` isn't too old
|
||||||
|
if [ ! "$(grep "/zsh$" "/etc/shells")" ] || \
|
||||||
|
env zsh -c "autoload -Uz 'is-at-least'; ! is-at-least 5.2"; then
|
||||||
|
yesno "Do you want the installer to automatically install 'zsh'?"
|
||||||
|
# try installing from 'brew' (Mac)
|
||||||
|
if hash "brew" 2>/dev/null; then
|
||||||
|
brew install "zsh" >/dev/null 2>&1
|
||||||
|
printf "${yellow}Installing zsh via Homebrew.. ${normal}\n"
|
||||||
|
# try installing from 'apt-get' (Debian/Ubuntu)
|
||||||
|
elif hash "apt-get" 2>/dev/null; then
|
||||||
|
apt-get install "zsh" >/dev/null 2>&1
|
||||||
|
# try installing from 'dnf' (Fedora)
|
||||||
|
elif hash "dnf" 2>/dev/null; then
|
||||||
|
dnf install "zsh" >/dev/null 2>&1
|
||||||
|
# try installing from 'pacman' (Arch)
|
||||||
|
elif hash "pacman" 2>/dev/null; then
|
||||||
|
pacman -S "zsh" >/dev/null 2>&1
|
||||||
|
else
|
||||||
|
printf "${red}Error: 'zsh' isn't available.. ${blue}please install manually!${normal}\n"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if Zim is already installed
|
# Check if Zim is already installed
|
||||||
if [ -e "${ZDOTDIR:-${HOME}}/.zimrc" ]; then
|
if [ -e "${ZDOTDIR:-${HOME}}/.zimrc" ]; then
|
||||||
printf "${red}Error: You already have Zim installed!${normal}\n";
|
printf "${red}Error: You already have Zim installed!${normal}\n";
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if other frameworks are installed
|
# Check if other frameworks are installed
|
||||||
|
@ -58,8 +80,6 @@ main() {
|
||||||
printf "${yellow}Prezto detected and backed up to\
|
printf "${yellow}Prezto detected and backed up to\
|
||||||
${HOME}/.zprezto_zimbackup${normal}\n"
|
${HOME}/.zprezto_zimbackup${normal}\n"
|
||||||
printf "${blue}This is done to prevent framework conflicts.${normal}\n"
|
printf "${blue}This is done to prevent framework conflicts.${normal}\n"
|
||||||
else
|
|
||||||
: # Do nothing
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Prevent the cloned repository from having insecure permissions.
|
# Prevent the cloned repository from having insecure permissions.
|
||||||
|
@ -70,16 +90,16 @@ main() {
|
||||||
if git --version | grep msysgit >/dev/null; then
|
if git --version | grep msysgit >/dev/null; then
|
||||||
printf "${red}Error: Windows/MSYS Git is not supported on Cygwin${normal}\n"
|
printf "${red}Error: Windows/MSYS Git is not supported on Cygwin${normal}\n"
|
||||||
printf "${red}Error: Make sure the Cygwin git package is installed and is first on the path${normal}\n"
|
printf "${red}Error: Make sure the Cygwin git package is installed and is first on the path${normal}\n"
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Back-up old zsh dotfiles
|
# Back-up old zsh dotfiles
|
||||||
if [ -f "${HOME}/.zshrc" ] || [ -L "${HOME}/.zshrc" ]; then
|
if [ -e "${HOME}/.zshrc" ]; then
|
||||||
printf "${yellow}Found ${HOME}/.zshrc! ${blue}Backing up to ${HOME}/.zshrc_zimbackup.${normal}\n"
|
printf "${yellow}Found ${HOME}/.zshrc! ${blue}Backing up to ${HOME}/.zshrc_zimbackup.${normal}\n"
|
||||||
mv "${HOME}/.zshrc" "${HOME}/.zshrc_zimbackup"
|
mv "${HOME}/.zshrc" "${HOME}/.zshrc_zimbackup"
|
||||||
fi
|
fi
|
||||||
if [ -f "${HOME}/.zlogin" ] || [ -L "${HOME}/.zlogin" ]; then
|
if [ -e "${HOME}/.zlogin" ]; then
|
||||||
printf "${yellow}Found ${HOME}/.zlogin!$ ${blue}Backing up to ${HOME}/.zlogin_zimbackup${normal}\n"
|
printf "${yellow}Found ${HOME}/.zlogin!$ ${blue}Backing up to ${HOME}/.zlogin_zimbackup${normal}\n"
|
||||||
mv "${HOME}/.zlogin" "${HOME}/.zlogin_zimbackup"
|
mv "${HOME}/.zlogin" "${HOME}/.zlogin_zimbackup"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue