a6a093ba2aed292f0610110c0e787aca57288319

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

installer: improve zsh binary path search in setup_shell

This changes the behavior to default to the binary found first in $PATH,
then checking it's actually in the shells file (/etc/shells).

If that fails go back to the previous behavior, but actually check that
the path obtained exists in the filesystem.

Co-authored-by: Joel Kuzmarski <leoj3n@gmail.com>

Diff

 1diff --git a/tools/install.sh b/tools/install.sh
 2index 8ec973832ce3edd16035960df18e5d872f42f41f..f91e0295409827fe96de1906bdde30ef45850cbe 100755
 3--- a/tools/install.sh
 4+++ b/tools/install.sh
 5@@ -117,7 +117,18 @@ setup_shell() {
 6 		return
 7 	fi
 8 
 9-	if ! chsh -s $(grep '^/.*/zsh$' "$shells_file" | tail -1); then
10+	# Get the path to the right zsh binary
11+	# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
12+	# 2. If that fails, get a zsh path from the shells file, then check it actually exists
13+	if ! zsh=$(which zsh) || ! grep -qx "$zsh" "$shells_file"; then
14+		if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
15+			error "no available zsh binary found. Change your default shell manually."
16+			return
17+		fi
18+	fi
19+
20+	# Actually change the default shell to zsh
21+	if ! chsh -s "$zsh"; then
22 		error "chsh command unsuccessful. Change your default shell manually."
23 	fi
24 }