Commit 9a832ccc authored by Marc Cornellà's avatar Marc Cornellà
Browse files

installer: use exit-on-error from the beginning

parent 27228d83
#!/bin/sh
set -e
# Test command existence (POSIX compatible)
command_exists() {
command -v "$@" >/dev/null 2>&1
}
main() { main() {
# Use colors, but only if connected to a terminal, and that terminal # Use colors, but only if connected to a terminal, and that terminal
# supports them. # supports them.
if which tput >/dev/null 2>&1; then if command_exists tput; then
ncolors=$(tput colors) ncolors=$(tput colors)
fi fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
...@@ -20,13 +28,9 @@ main() { ...@@ -20,13 +28,9 @@ main() {
NORMAL="" NORMAL=""
fi fi
# Only enable exit-on-error after the non-critical colorization stuff, if ! command_exists zsh; then
# which may fail on systems lacking tput or terminfo
set -e
if ! command -v zsh >/dev/null 2>&1; 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 exit 1
fi fi
if [ ! -n "$ZSH" ]; then if [ ! -n "$ZSH" ]; then
...@@ -36,7 +40,7 @@ main() { ...@@ -36,7 +40,7 @@ main() {
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 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
...@@ -47,7 +51,7 @@ main() { ...@@ -47,7 +51,7 @@ main() {
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 -v git >/dev/null 2>&1 || { command_exists git || {
echo "Error: git is not installed" echo "Error: git is not installed"
exit 1 exit 1
} }
...@@ -82,7 +86,7 @@ main() { ...@@ -82,7 +86,7 @@ main() {
TEST_CURRENT_SHELL=$(basename "$SHELL") TEST_CURRENT_SHELL=$(basename "$SHELL")
if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
# If this platform provides a "chsh" command (not Cygwin), do it, man! # If this platform provides a "chsh" command (not Cygwin), do it, man!
if hash chsh >/dev/null 2>&1; then if command_exists chsh; then
printf "${BLUE}Time to change your default shell to zsh!${NORMAL}\n" printf "${BLUE}Time to change your default shell to zsh!${NORMAL}\n"
chsh -s $(grep /zsh$ /etc/shells | tail -1) chsh -s $(grep /zsh$ /etc/shells | tail -1)
# Else, suggest the user do so manually. # Else, suggest the user do so manually.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment