Handle systems where /etc/shells does not exist

This commit is contained in:
Fredrik Fornwall 2015-10-30 12:55:44 +01:00
parent e44aa50301
commit 1d5ef285eb

View File

@ -24,11 +24,13 @@ main() {
# which may fail on systems lacking tput or terminfo # which may fail on systems lacking tput or terminfo
set -e set -e
if [ -f /etc/shells ]; then
CHECK_ZSH_INSTALLED=$(grep /zsh$ /etc/shells | wc -l) CHECK_ZSH_INSTALLED=$(grep /zsh$ /etc/shells | wc -l)
if [ ! $CHECK_ZSH_INSTALLED -ge 1 ]; then if [ ! $CHECK_ZSH_INSTALLED -ge 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
fi fi
fi
unset CHECK_ZSH_INSTALLED unset CHECK_ZSH_INSTALLED
if [ ! -n "$ZSH" ]; then if [ ! -n "$ZSH" ]; then
@ -90,12 +92,12 @@ main() {
TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)') TEST_CURRENT_SHELL=$(expr "$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 [ -f /etc/shells ] && hash chsh >/dev/null 2>&1; 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.
else else
printf "I can't change your shell automatically because this system does not have chsh.\n" printf "I can't change your shell automatically because this system does not have chsh and /etc/shells.\n"
printf "${BLUE}Please manually change your default shell to zsh!${NORMAL}\n" printf "${BLUE}Please manually change your default shell to zsh!${NORMAL}\n"
fi fi
fi fi